Skip to content

Add constrained JSON generation for extraction and classification #524

Description

@sauravpanda

Suggested priority: P2 — application-facing capability.

Add a constrained-decoding API so applications can request structured extraction/classification results with machine-checkable output. The reviewed sampling and request APIs do not expose a JSON/schema constraint.

Scope and acceptance criteria

  • Start with a documented JSON grammar and a deliberately bounded JSON Schema subset; explicitly reject unsupported schema features.
  • Apply an incremental token constraint before sampling; handle tokens containing partial UTF-8 sequences and multiple grammar characters.
  • Expose the feature in core generation, browser bindings/SDK, and the server request API with consistent semantics.
  • Permit EOS only at valid completion points and surface unsatisfiable constraints as a clear error.
  • Distinguish complete valid output from cancellation or token-budget exhaustion; never label truncated JSON as schema-valid.
  • Ensure greedy, sampled, streaming, and batch paths use the same constraints; define or disable incompatible speculative paths.
  • Test escaping, Unicode, nesting, enums, required fields, arrays, invalid schemas, and impossible constraints.
  • Add an extraction/classification example and benchmark constraint overhead.

Initial delivery should document its supported subset instead of claiming full JSON Schema compatibility. Valid JSON/schema conformance does not guarantee factual extraction accuracy.

Implementation starting points: sampling, generation, server requests, browser bindings.

Activity

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

    enhancementNew feature or improvement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions