Skip to content

Structured output (JSON schema) for LLM generation #1528

Closed as duplicate
Closed as duplicate

Description

@msluszniak

Problem description

LLM generation cannot be forced to match a JSON schema, so apps put the schema in the prompt. With Llama 3.2 1B that gave 2/20 valid outputs (review).

Proposed solution

Grammar-constrained decoding (mask logits per step, e.g. via xgrammar), exposed as responseFormat: { type: 'json_schema', schema } on generate / sendMessage.

Alternative solutions

Prompt + validate + retry: what users do today, unreliable on small models.

Benefits to React Native ExecuTorch

Reliable structured output for extraction, classification and tool calling.

Additional context

Blocked on the LLM runner rewrite; the current runner uses upstream's sampler.

Activity

  1. added
    user expThis issue tackles problems with user experience e.g. overcomplicated API
    on Oct 12, 2026
  2. added theissue type on Oct 12, 2026
  3. msluszniak commented on Oct 12, 2026

    @msluszniak
    MemberAuthor
  4. barhanc commented on Oct 12, 2026

    @barhanc
    Member

    Isn't this duplicate of #1377?

  5. msluszniak commented on Oct 12, 2026

    @msluszniak
    MemberAuthor

    Yes, it's duplicate

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

    user expThis issue tackles problems with user experience e.g. overcomplicated API

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions