Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This pull request fixes a "Bad request" error that occurs when using f.json() or a bare f.object() in a structured output with Anthropic models. The Anthropic API requires that all object schemas in a structured output must have additionalProperties explicitly set to false, which is incompatible with arbitrary JSON objects.

This PR introduces the following changes:

  • Schema Validation: The cleanSchemaForAnthropic function in src/ax/ai/anthropic/api.ts has been updated to detect unsupported schemas (i.e., those representing arbitrary JSON objects). When such a schema is found, it throws a descriptive error with suggested workarounds.
  • Schema Cleaning: For all valid structured object schemas, the function now recursively sets additionalProperties: false to ensure compliance with the Anthropic API.
  • New Test Case: A new test has been added to src/ax/ai/anthropic/api.test.ts to verify that the correct error is thrown for unsupported schemas.

This solution provides a better developer experience by catching the error early and providing clear guidance, while also ensuring that valid schemas are correctly processed.

Fixes #458


PR created automatically by Jules for task 4936239086328272522 started by @dosco

…red outputs

Anthropic models do not support arbitrary JSON objects (e.g. f.json() or f.object() with no properties) in structured outputs. This commit adds a validation step that throws a descriptive error when this unsupported schema is detected, preventing the API from returning a cryptic "Bad Request" error.

For valid structured objects, this commit also ensures `additionalProperties: false` is set recursively, which is required by the Anthropic API.

A new test case has been added to verify the error-throwing behavior.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@dosco dosco marked this pull request as ready for review November 28, 2025 19:12
@dosco dosco merged commit 7db81c5 into main Nov 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad request with f.json() in f.object() used as output with Anthropic models

2 participants