1515from pydantic_ai ._instrumentation import InstrumentationNames
1616
1717from . import _function_schema , _utils , messages as _messages
18+ from ._json_schema import JsonSchema
1819from ._run_context import AgentDepsT , RunContext
1920from .exceptions import ModelRetry , ToolRetryError , UserError
2021from .output import (
@@ -226,6 +227,9 @@ def mode(self) -> OutputMode:
226227 def allows_text (self ) -> bool :
227228 return self .text_processor is not None
228229
230+ def dump (self ) -> JsonSchema :
231+ raise NotImplementedError ()
232+
229233 @classmethod
230234 def build ( # noqa: C901
231235 cls ,
@@ -405,6 +409,13 @@ def __init__(
405409 def mode (self ) -> OutputMode :
406410 return 'auto'
407411
412+ def dump (self ) -> JsonSchema :
413+ if self .toolset :
414+ toolset_processors = [self .toolset .processors [k ] for k in self .toolset .processors ]
415+ processors_union = UnionOutputProcessor (toolset_processors ).object_def .json_schema
416+ return processors_union
417+ return self .processor .object_def .json_schema
418+
408419
409420@dataclass (init = False )
410421class TextOutputSchema (OutputSchema [OutputDataT ]):
@@ -425,6 +436,9 @@ def __init__(
425436 def mode (self ) -> OutputMode :
426437 return 'text'
427438
439+ def dump (self ) -> JsonSchema :
440+ return {'type' : 'string' }
441+
428442
429443class ImageOutputSchema (OutputSchema [OutputDataT ]):
430444 def __init__ (self , * , allows_deferred_tools : bool ):
@@ -450,6 +464,9 @@ def __init__(
450464 )
451465 self .processor = processor
452466
467+ def dump (self ) -> JsonSchema :
468+ return self .object_def .json_schema
469+
453470
454471class NativeOutputSchema (StructuredTextOutputSchema [OutputDataT ]):
455472 @property
@@ -523,6 +540,11 @@ def __init__(
523540 def mode (self ) -> OutputMode :
524541 return 'tool'
525542
543+ def dump (self ) -> JsonSchema :
544+ toolset_processors = [self .toolset .processors [k ] for k in self .toolset .processors ]
545+ processors_union = UnionOutputProcessor (toolset_processors ).object_def .json_schema
546+ return processors_union
547+
526548
527549class BaseOutputProcessor (ABC , Generic [OutputDataT ]):
528550 @abstractmethod
@@ -725,7 +747,10 @@ def __init__(
725747 json_schemas : list [ObjectJsonSchema ] = []
726748 self ._processors = {}
727749 for output in outputs :
728- processor = ObjectOutputProcessor (output = output , strict = strict )
750+ if isinstance (output , ObjectOutputProcessor ):
751+ processor = output
752+ else :
753+ processor = ObjectOutputProcessor (output = output , strict = strict )
729754 object_def = processor .object_def
730755
731756 object_key = object_def .name or output .__name__
0 commit comments