Repository navigation
fix: preserve Cloudflare JSON Schema requests - #129
stackbilt-admin merged 8 commits into
Conversation
f0d2469 to
836e212
Compare
stackbilt-admin
left a comment
There was a problem hiding this comment.
Thanks for picking up #127. Sending response_format.json_schema in Cloudflare's native shape is the right direction, and the forwarding test does catch the original drop. Right now, though, the capability report, the request that's actually sent, and the streaming behavior disagree with each other, so we need changes before this can merge.
Requested changes
-
Gate forwarding on the capability.
formatRequestbuildsnativeJsonSchemafromresponse_format.type === 'json_schema'alone, and the newsupportsStructuredOutputflag is never consulted. Please forward the schema natively only when the model declares support. Otherwise, reject clearly (see item 2) and make the route plan report it. Prompting with the schema (reported asemulated) is acceptable only when the caller explicitly permits it, because a prompt instruction doesn't give native schema enforcement. -
Make the streaming boundary consistent, and don't block fallback.
- The guard checks
request.stream, butCloudflareProvider.streamResponse()callsformatRequest()first and addsstream: trueafterwards, so direct streaming callers skip the guard and sendstream: truetogether withresponse_format: json_schema. Please enforce the rule on every streaming path, for example by passing the stream flag intoformatRequestor checking instreamResponse. - The guard throws
ConfigurationError, and the factory never falls back on that error (getFallbackDecision). Cloudflare is first in the default chain, so a streaming JSON-schema request fails outright even when a later provider supports it natively. Rejecting the unsupported combination is reasonable; preventing fallback isn't. Emulate only when the caller explicitly permits it; otherwise reject consistently and allow routing to a compatible provider. Please add a test that goes through the factory.
- The guard checks
-
Make route reporting match what's sent.
routeDegradationsreportsemulatedfor Cloudflare models without the flag, but the adapter injects no instruction forjson_schema. Your test asserts no system message is added, so nothing is actually emulated.- For stream +
json_schemaon Cloudflare, the plan reports executable with nofaileddegradation, but the adapter throws. - In the other direction,
json_objecton flagged models now reports no degradation, while the adapter still emulatesjson_objectwith a prompt instruction.
Please make
getGatewayRoutePlandescribe exactly what the adapter does in each of these cases. -
Make the new public field optional.
GatewayRouteCapabilityReport.supportsStructuredOutputis a requiredbooleanon an exported interface, which breaks consumers who build or mock that type by hand (the reasonGatewayRoutePlan.executableis optional). Please make itsupportsStructuredOutput?: boolean.
Also please cover the paths that bypass the standard formatter. formatAnthropicViaCloudflareRequest and the raw Llama vision path still drop the schema silently. At minimum they should report or reject consistently with item 3, rather than reproducing the original silent drop.
Tests we'd like to see: a model without the flag; streaming through streamResponse(); factory fallback for stream + schema; a route plan for stream + schema on Cloudflare; and one route-plan assertion for a non-flagged Cloudflare model. The current route-plan test passes on main apart from the new field.
Advisory (not blocking on its own)
- Flag naming: #113 proposes separate
supportsJsonObject/supportsJsonSchemacapabilities. Since a public name can't be removed without a major version, aligning now (for example naming thissupportsJsonSchema) would avoid locking in a broader flag than the behavior it controls. This PR doesn't need to complete #113. - Model compatibility evidence: we haven't verified which Cloudflare models reject
json_schemaor return "JSON Mode couldn't be met", so treat that as a risk pending docs or live results. Please cite a source for the@cf/zai-org/glm-5.3flag (llama-3.3-70b-fp8-fast is on Cloudflare's JSON mode list), and keepCloudflareProvider.getModelCapabilities()reading from the same source so the two can't drift. Mapping "JSON Mode couldn't be met" to a clear error inwrapCFErrorwould be a good addition. - A CHANGELOG entry. With the public additions this would be a minor release.
CI is waiting on maintainer approval for fork PRs. We'll require normal CI to pass on the final commit before merging. The failing supply-chain check is a known repo-level problem unrelated to this PR, tracked in #137.
|
Implemented the requested Cloudflare structured-output fixes in commit
Validation passed: |
|
Thanks for the thorough update. Before we can review it again, it needs a rebase: #139 (released as 1.24.0) changed several of the same files ( When resolving the conflicts, please keep two things from #139:
Please also keep |
21b5113 to
6247032
Compare
|
Thanks for the rebase and the follow-up commits. Streaming is now checked on every path, the factory falls back on Blocking
Still open from the earlier review
Also needed
Optional: map Workers AI's "JSON Mode couldn't be met" error in |
6247032 to
249285f
Compare
|
Thanks for the update. It addresses both blocking items. The capability now records the request shape per model, from one table shared by the provider and the catalog: models on Cloudflare's JSON mode list get the bare schema, and glm-5.3 and glm-5.3-flash get One item from the earlier review is still open:
Minor, not blocking: in Optional, still open: mapping Workers AI's "JSON Mode couldn't be met" error in We plan to ship this as a minor release. |
# Conflicts: # CHANGELOG.md # src/providers/cloudflare.ts
…dels - StructuredOutputUnsupportedError no longer counts as a Cloudflare health failure; it is thrown before any Workers AI call. - Unpinned json_schema requests plan only Cloudflare models with native support, unless prompt emulation is allowed. - README and CHANGELOG cover the new error, fields and route plan changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore: release 1.28.0 - Native JSON Schema output on Cloudflare Workers AI (#129, closes #127) - Upgrade note for Cloudflare json_schema behaviour - Checkpoint and README version references updated Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: 1.28.0 review fixes for the checkpoint, CHANGELOG and README Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Kurt Overmier <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
json_schemarequests by forwarding the native JSON Schema payload.Fixes #127
Issue: #127
Validation
npm testnpm run typechecknpm run buildnpm run test:worker-importgit diff --check