@@ -385,7 +385,7 @@ def _build_processor(
385385
386386 return UnionOutputProcessor (outputs = outputs , strict = strict , name = name , description = description )
387387
388- def build_json_schema (self ) -> JsonSchema :
388+ def build_json_schema (self ) -> JsonSchema : # noqa: C901
389389 # allow any output with {'type': 'string'} if no constraints
390390 if not any ([self .allows_deferred_tools , self .allows_image , self .object_def , self .toolset ]):
391391 return TypeAdapter (str ).json_schema ()
@@ -407,19 +407,23 @@ def build_json_schema(self) -> JsonSchema:
407407 json_schema = tool_processor .object_def .json_schema
408408 if k := tool_processor .outer_typed_dict_key :
409409 json_schema = json_schema ['properties' ][k ]
410- json_schemas .append (json_schema )
410+ if json_schema not in json_schemas :
411+ json_schemas .append (json_schema )
411412
412413 elif self .allows_text :
413414 json_schema = TypeAdapter (str ).json_schema ()
414415 json_schemas .append (json_schema )
415416
416417 if self .allows_deferred_tools :
417418 json_schema = TypeAdapter (DeferredToolRequests ).json_schema (mode = 'serialization' )
418- json_schemas .append (json_schema )
419+ if json_schema not in json_schemas :
420+ json_schemas .append (json_schema )
421+
419422 if self .allows_image :
420423 json_schema = TypeAdapter (_messages .BinaryImage ).json_schema ()
421424 json_schema = {k : v for k , v in json_schema ['properties' ].items () if k in ['data' , 'media_type' ]}
422- json_schemas .append (json_schema )
425+ if json_schema not in json_schemas :
426+ json_schemas .append (json_schema )
423427
424428 if len (json_schemas ) == 1 :
425429 return json_schemas [0 ]
0 commit comments