| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Resolve inconsistency between schema and actual output when using Pydantic models with field aliases as tool return types: - Add by_alias=True parameter to model_dump() call in func_metadata.py - Add comprehensive test case to verify alias consistency - Ensure schema generation and structured output use same aliased field names Before: Schema shows "first", "second" but output uses "field_first", "field_second" After: Both schema and output consistently use aliased field names
There was a problem hiding this comment.
Thank you for working on this!
QQ:
Added comprehensive test case test_structured_output_aliases() that verifies both schema generation and output use consistent alias names
I don't see any tests added, please can this be checked?
Sorry, something went wrong.
Add comprehensive test_structured_output_aliases() that verifies: - Schema generation uses aliased field names - Structured output uses same aliased field names - Both explicit values and default values work correctly - Ensures consistency between schema and actual tool output
|
I’m wondering why I can’t get some tests to pass on Windows.
|
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fix Pydantic field alias consistency in structured output
Summary
Fixes issue #1073. Fix inconsistency between schema and structured output when using Pydantic models with field aliases in tool return types. The schema would display aliased field names but the actual output would use original field names.
Motivation and Context
When defining Pydantic models with field aliases for tool return types, there was an inconsistency where:
This inconsistency made it difficult for clients to reliably consume structured tool outputs, as the field names in the schema didn't match the actual response data.
How Has This Been Tested?
Breaking Changes
No breaking changes. This is a bug fix that makes the behavior consistent with what the schema advertises. Users who were working around this inconsistency may need to update their code to use the aliased field names consistently.
Types of changes
Checklist
Additional context
The fix was a simple one-line change adding by_alias=True to the model_dump() call in func_metadata.py:114. This ensures that when Pydantic models are serialized for structured output, they use the same field names that appear in the generated JSON schema.
The test case covers both the schema generation and the actual output conversion to ensure they remain consistent. This addresses the core issue described in the original bug report where the schema and output used different field naming conventions.
Technical Details
Before the fix:
After the fix:
Code change: