@@ -112,7 +112,9 @@ def pre_parse_json(self, data: dict[str, Any]) -> dict[str, Any]:
112112
113113
114114def func_metadata (
115- func : Callable [..., Any ], skip_names : Sequence [str ] = ()
115+ func : Callable [..., Any ],
116+ skip_names : Sequence [str ] = (),
117+ output_schema : dict [str , Any ] | None = None ,
116118) -> FuncMetadata :
117119 """Given a function, return metadata including a pydantic model representing its
118120 signature.
@@ -137,7 +139,6 @@ def func_metadata(
137139 sig = _get_typed_signature (func )
138140 params = sig .parameters
139141 dynamic_pydantic_model_params : dict [str , Any ] = {}
140- output_schema : dict [str , Any ] | None = None
141142 globalns = getattr (func , "__globals__" , {})
142143 for param in params .values ():
143144 if param .name .startswith ("_" ):
@@ -183,14 +184,17 @@ def func_metadata(
183184 __base__ = ArgModelBase ,
184185 )
185186
186- # TODO this could be moved to a constant or passed in as param as per skip_names
187- ignore = [inspect .Parameter .empty , None , types .Image ]
188- if sig .return_annotation not in ignore :
189- type_schema = TypeAdapter (sig .return_annotation ).json_schema ()
190- if type_schema .get ("type" , None ) == "object" :
191- output_schema = type_schema
187+ return_output_schema = output_schema
192188
193- return FuncMetadata (arg_model = arguments_model , output_schema = output_schema )
189+ if return_output_schema is None :
190+ # TODO this could be moved to a constant or passed in as param as per skip_names
191+ ignore = [inspect .Parameter .empty , None , types .Image ]
192+ if sig .return_annotation not in ignore :
193+ type_schema = TypeAdapter (sig .return_annotation ).json_schema ()
194+ if type_schema .get ("type" , None ) == "object" :
195+ return_output_schema = type_schema
196+
197+ return FuncMetadata (arg_model = arguments_model , output_schema = return_output_schema )
194198
195199
196200def _get_typed_annotation (annotation : Any , globalns : dict [str , Any ]) -> Any :
0 commit comments