@@ -171,6 +171,7 @@ def func_metadata(
171171 func : Callable [..., Any ],
172172 skip_names : Sequence [str ] = (),
173173 structured_output : bool | None = None ,
174+ schema_generator : type [GenerateJsonSchema ] | None = None ,
174175) -> FuncMetadata :
175176 """Given a function, return metadata including a Pydantic model representing its signature.
176177
@@ -201,6 +202,8 @@ def func_metadata(
201202 - TypedDict - converted to a Pydantic model with same fields
202203 - Dataclasses and other annotated classes - converted to Pydantic models
203204 - Generic types (list, dict, Union, etc.) - wrapped in a model with a 'result' field
205+ schema_generator: Optional Pydantic JSON schema generator to use when producing
206+ structured output schemas. Defaults to strict schema generation.
204207
205208 Returns:
206209 A FuncMetadata object containing:
@@ -302,7 +305,10 @@ def func_metadata(
302305 original_annotation = sig .return_annotation
303306
304307 output_model , output_schema , wrap_output = _try_create_model_and_schema (
305- original_annotation , return_type_expr , func .__name__
308+ original_annotation ,
309+ return_type_expr ,
310+ func .__name__ ,
311+ schema_generator = schema_generator ,
306312 )
307313
308314 if output_model is None and structured_output is True :
@@ -323,6 +329,7 @@ def _try_create_model_and_schema(
323329 original_annotation : Any ,
324330 type_expr : Any ,
325331 func_name : str ,
332+ schema_generator : type [GenerateJsonSchema ] | None = None ,
326333) -> tuple [type [BaseModel ] | None , dict [str , Any ] | None , bool ]:
327334 """Try to create a model and schema for the given annotation without warnings.
328335
@@ -401,7 +408,7 @@ def _try_create_model_and_schema(
401408 # If we successfully created a model, try to get its schema
402409 # Use StrictJsonSchema to raise exceptions instead of warnings
403410 try :
404- schema = model .model_json_schema (schema_generator = StrictJsonSchema )
411+ schema = model .model_json_schema (schema_generator = schema_generator or StrictJsonSchema )
405412 except (
406413 PydanticUserError ,
407414 TypeError ,
0 commit comments