Skip to content

Fix enum schema flattening #600

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

westonbrown
Copy link

Description

This PR fixes a JSON schema validation error that occurs when using enum types in tool function parameters with certain model providers (e.g., Bedrock via LiteLLM).

The issue was that Pydantic generates JSON schemas with $ref references and $defs sections for enum types, but some model providers don't support JSON Schema $ref references. This caused "JSON schema is invalid" errors when calling tools with enum parameters.

The fix adds a _resolve_json_schema_references() function to the decorator.py file that flattens the schema by replacing all $ref occurrences with their actual definitions from the $defs section. This ensures compatibility with all model providers while maintaining the same functionality.

Related Issues

Fixes #565

Documentation PR

N/A - No documentation changes required as this is an internal implementation fix that doesn't change the API.

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare
  • Verified the fix resolves the original issue where tools with enum parameters failed with LiteLLM/Bedrock

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@poshinchen poshinchen self-assigned this Aug 4, 2025
@dbschmigelski
Copy link
Member

Hi, can you point out which model providers you noticed don't support JSON Schema $ref references. There are benefits which we likely would want to retain by keeping references, like reducing token usage from repetition and allowing recursive strictly typed schemas.

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.

3 participants