Skip to content

Refuse a card whose capability input schema is not an object schema #1

Closed

Description

@Balanov

What is missing today

validateCard in latch.mjs:119 checks that every capability of a card declares a usable input schema. The check is at latch.mjs:154:

validateInput({}, capability.input || {}, `${at}.input`).forEach((error) => {
  if (error.includes("must be object")) errors.push(`${at}.input must be an object schema`);
});

It never fires. validateInput produces the message must be object only when the declared type is exactly object, and a schema whose type is object always matches the empty object that is validated against it, so no error is produced for it. A schema whose type is string produces must be string, a schema whose type is array produces must be array, and a schema with no type produces no error at all. None of those messages contain must be object.

The consequence is that the card is accepted with a capability input schema that is not an object schema. A card with "input": {"type": "string"} passes validateCard, so latch validate card.json prints {"valid": true, ...} and createLatchServer starts. At request time process validates the input against that same schema (latch.mjs:400), so an ask with "input": "hello" passes validation and the provider handler receives a string where the protocol says the input is an object. The card check and the request check agree with each other and both disagree with the protocol.

SPEC.md defines the field as an object: the envelope table in section 3 lists input as "Capability input object", and the capability schema in section 2 is documented as an object schema. The error text in the code says the same thing: must be an object schema.

What done means

  • validateCard refuses a card whose capability declares an input schema that does not describe an object. The error names the capability id and the declared type, and the card is refused with invalid_card and HTTP 422 as today.
  • The check is made on the schema itself, not on the text of an error message produced by validating {}. A schema whose type is string, a schema whose type is array, and a type list that does not contain object are all refused.
  • A capability input schema with no declared type keeps its current behaviour and is not refused by this change.
  • The cards that ship with the repository still validate: the demo provider card in latch.mjs, the card written by latch init (latch.mjs:986) and providers/php/latch.json.
  • ask and quote still validate the input against the capability schema at request time and still refuse a bad input with invalid_input and HTTP 422.
  • npm test passes, with one test for a card whose capability input schema is not an object schema.
  • node --check latch.mjs passes and node latch.mjs demo --trace examples/trace.json still produces the same trace.

Boundary

  • Zero runtime dependencies. Node.js 20+ and the standard library are enough.
  • No change to the wire contract, to the envelope, to the error codes or to the HTTP status codes.
  • No change to the request validation in validateInput; the change is in the card check.
  • No network call, no telemetry, no account, no service, and no change to the demo provider behaviour.
  • Do not add vendor links or endorsements to the documentation, and do not trade a documentation change for this fix.

Activity

  1. added
    help wanted
    good first issue
    on Nov 14, 2026
  2. Balanov commented on Nov 15, 2026

    @Balanov
    OwnerAuthor

    Thank you for the report, and for the fix. @ShahadatTest opened pull request #2 and it is merged: the card validation now reads the declared input schema type instead of matching an error message, so a card whose input is not an object schema is refused with invalid_card and HTTP 422, naming the capability and the declared type. SPEC.md says the same thing now. It ships in latch 0.2.1.

    Thank you for the report and for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions