Skip to content

Workers AI silently drops json_schema while the route plan reports no degradation #127

Closed

Description

@stackbilt-admin

Problem

On Workers AI, a json_schema request is silently downgraded to plain text, while the route plan reports no degradation.

Measured (@stackbilt/[email protected], local workerd via Miniflare, fake AI binding that records its input; no live model)

Tested with pinned @cf/zai-org/glm-5.3-flash and @cf/meta/llama-3.3-70b-instruct-fp8-fast, same result for both:

Request Sent to ai.run Returned when the model outputs prose
response_format: { type: 'json_schema', ... } no response_format, no schema, no JSON instruction 'not json at all', no error
response_format: { type: 'json_object' } no response_format; JSON instruction added to the system prompt 'not json at all', no error

For the same kind of request, getGatewayRoutePlan(normalizeCanonicalRequest({ ..., output: { kind: 'json_schema', ... }, requirements: { structuredOutput: true } }), ['cloudflare']) returns executable: true, degradations: [].

In the published dist/providers/cloudflare.js, the only response_format read is request.response_format?.type === 'json_object'. The Groq, OpenAI, NVIDIA and Cerebras adapters do forward response_format.

Why it matters

Cloudflare is the primary route. The caller's schema disappears with no signal, so the model is never told the shape it should produce. The README does warn that the plan isn't a guarantee of native JSON-schema support, but dropping the schema entirely goes further than that.

Related: canonicalToLLMRequest() also drops requirements, so a caller's structuredOutput: true can't reach execution.

Expected

Any of these, ideally the first where the model supports it:

  1. Forward native JSON mode for supported models. Cloudflare's JSON mode docs use json_schema holding the schema directly, not OpenAI's { name, schema, strict } wrapper, and they say streaming isn't supported and that a "JSON Mode couldn't be met" error must be handled. That page lists a limited set of models, including Llama 3.3 fp8-fast but not GLM-5.3 Flash, so per-model verification is needed.
  2. Otherwise inject the schema as an instruction and report action: 'emulated'.
  3. Otherwise fail with a clear error, and report action: 'failed' in the plan.

Relationship to existing issues

Narrower and more concrete than #113, which covers distinct supportsJsonObject/supportsJsonSchema metadata and visible emulation. This is the specific silent-drop bug and could be fixed first.

Scope

This records what the adapter sends. It doesn't measure how real models behave.

Activity

  1. added
    bug
    P1-high
    on Oct 31, 2026
  2. mikemikimike commented on Oct 31, 2026

    @mikemikimike
    Contributor

    Implemented in #129.

    The Cloudflare Workers AI adapter now forwards native json_schema requests for supported models, reports structured-output capability accurately during route planning, and rejects unsupported streaming JSON Schema requests with a clear error. Regression tests cover forwarding, routing, and the streaming boundary.

    Validation: npm test (792 passed), npm run typecheck, npm run build, and npm run test:worker-import.

  3. mikemikimike commented on Nov 7, 2026

    @mikemikimike
    Contributor

    Implemented the requested Cloudflare structured-output fixes in PR #129.

    The adapter now sends the documented raw JSON Schema shape for Workers AI JSON Mode models and the { name, schema, strict } wrapper for GLM-5.3 and GLM-5.3 Flash. Model capability data is sourced from one mapping, unknown capabilities remain unset, and schema emulation is an explicit typed option. Vision, streaming rejection, factory fallback, route planning, documentation, and changelog coverage were added or corrected.

    Validation: npm test (914 tests), npm run typecheck, npm run test:worker-import, package smoke test, and npm audit --omit=dev.

  4. added a commit that references this issue on Nov 9, 2026
    2d5bf37
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

    P1-highbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions