Skip to content

Commit 18456a4

Browse files
authored
fix(anthropic): keep enum and const as structured-output constraints (#7558)
* fix(anthropic): keep enum and const as structured-output constraints The SDK's transformJSONSchema pops every keyword it recognises and stringifies whatever is left into the node's description. It has no branch for enum or const, so both were silently demoted from grammar constraints into prose, leaving native structured outputs unenforced for them on every Anthropic and Azure Anthropic agent block. Lift enum and const out before the transform and re-attach them after, so the transform's sanitising is preserved verbatim. Only lift the shapes the API grammar-checks: a non-empty enum of primitives matching the node's declared type, and a primitive const. Anything else stays in place and is demoted exactly as before, since sending it would make the API reject the whole request. * chore(anthropic): type the structured-output test helper instead of any Replaces the two Record<string, any> casts in the new test helper with a WireSchemaNode interface describing the subset of the wire schema the assertions read back, per the repo's no-any rule. * test(anthropic): lock the structured-output schema non-mutation invariant The builder deep-clones before walking so it never deletes enum/const from the caller's schema object. Agent blocks inside a parallel or loop reuse the same responseFormat object across iterations, so losing that clone would strip the constraints from every iteration after the first. Verified the test fails when the clone is removed.
1 parent 0049514 commit 18456a4

Sorry, this diff is taking too long to generate.

It may be too large to display on GitHub.