Repository navigation
Description
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:
- Forward native JSON mode for supported models. Cloudflare's JSON mode docs use
json_schemaholding 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. - Otherwise inject the schema as an instruction and report
action: 'emulated'. - 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
mikemikimike commentedon Oct 31, 2026
Implemented in #129.
The Cloudflare Workers AI adapter now forwards native
json_schemarequests 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, andnpm run test:worker-import.mikemikimike commentedon Nov 7, 2026
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, andnpm audit --omit=dev.chore: release 1.28.0 (#153)