-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Optional Fields in Agent Output Cause JSON Schema Error with AWS Bedrock #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looking into this, thanks for the report! |
@samDobsonDev I think there's something specific about Bedrock that isn't working. When I use Claude directly, it works ok (script below). I don't have a way to repro on bedrock - do you have a contact there that can help? Another thing that might help is to change output_type to this:
Can you try that and see if it helps? Code that worked for me hitting claude directly:
|
Hi @rm-openai. Just tried your suggestion of:
...but ran into the same error:
We do have a contact we can reach out to, I'll see if I can maybe get in touch with them and see if they've experienced anything like this before |
So I managed to "fix" this by removing the Optional wrapper and instead using default values with the Pydantic
I'm now using:
I also tried using something like...
...but this also caused the same exception to be thrown once the request reaches Bedrock. |
@samDobsonDev that's really strange. Makes me think there's something wrong about the Bedrock JSON schema validator. Especially given that it works with Anthropic directly. Anyway I'm glad you managed to get a fix working! |
Summary:
When using the OpenAI Agents SDK with a custom agent output schema that includes
Optional
fields (defined using Pydantic), the request to AWS Bedrock fails with a 400 Bad Request error. The error indicates that the generated JSON schema is invalid according to JSON Schema Draft 2020-12. If I remove theOptional
fields, the request succeeds, but then the model is forced to always populate those fields, which is not the desired behaviour.Environment:
Agents SDK Version: 0.0.12
Model: Claude 3.5 Sonnet via AWS Bedrock with LiteLLM
Steps to Reproduce
Optional
, such as this example:LitellmModel
BedrockError: {"message":"The model returned the following errors: tools.0.custom.input_schema: JSON schema is invalid. It must match JSON Schema draft 2020-12."}
Expected Behavior
The text was updated successfully, but these errors were encountered: