@@ -235,8 +235,45 @@ async def check_call(args):
235235
236236
237237def test_complex_function_json_schema ():
238+ """Test JSON schema generation for complex function arguments.
239+
240+ Note: Different versions of pydantic output slightly different
241+ JSON Schema formats for model fields with defaults. The format changed in 2.9.0:
242+
243+ 1. Before 2.9.0:
244+ {
245+ "allOf": [{"$ref": "#/$defs/Model"}],
246+ "default": {}
247+ }
248+
249+ 2. Since 2.9.0:
250+ {
251+ "$ref": "#/$defs/Model",
252+ "default": {}
253+ }
254+
255+ Both formats are valid and functionally equivalent. This test accepts either format
256+ to ensure compatibility across our supported pydantic versions.
257+
258+ This change in format does not affect runtime behavior since:
259+ 1. Both schemas validate the same way
260+ 2. The actual model classes and validation logic are unchanged
261+ 3. func_metadata uses model_validate/model_dump, not the schema directly
262+ """
238263 meta = func_metadata (complex_arguments_fn )
239- assert meta .arg_model .model_json_schema () == {
264+ actual_schema = meta .arg_model .model_json_schema ()
265+
266+ # Create a copy of the actual schema to normalize
267+ normalized_schema = actual_schema .copy ()
268+
269+ # Normalize the my_model_a_with_default field to handle both pydantic formats
270+ if 'allOf' in actual_schema ['properties' ]['my_model_a_with_default' ]:
271+ normalized_schema ['properties' ]['my_model_a_with_default' ] = {
272+ '$ref' : '#/$defs/SomeInputModelA' ,
273+ 'default' : {}
274+ }
275+
276+ assert normalized_schema == {
240277 "$defs" : {
241278 "InnerModel" : {
242279 "properties" : {"x" : {"title" : "X" , "type" : "integer" }},
0 commit comments