Skip to content

Commit 89c9bb6

Browse files
DouweMclaude[bot]
andauthored
Support NativeOutput with FunctionModel (#2843)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Douwe Maan <[email protected]>
1 parent 085a4c3 commit 89c9bb6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pydantic_ai_slim/pydantic_ai/models/function.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
UserContent,
3232
UserPromptPart,
3333
)
34-
from ..profiles import ModelProfileSpec
34+
from ..profiles import ModelProfile, ModelProfileSpec
3535
from ..settings import ModelSettings
3636
from ..tools import ToolDefinition
3737
from . import Model, ModelRequestParameters, StreamedResponse
@@ -111,6 +111,12 @@ def __init__(
111111
stream_function_name = self.stream_function.__name__ if self.stream_function is not None else ''
112112
self._model_name = model_name or f'function:{function_name}:{stream_function_name}'
113113

114+
# Use a default profile that supports JSON schema and object output if none provided
115+
if profile is None:
116+
profile = ModelProfile(
117+
supports_json_schema_output=True,
118+
supports_json_object_output=True,
119+
)
114120
super().__init__(settings=settings, profile=profile)
115121

116122
async def request(

tests/test_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ def return_city_location(messages: list[ModelMessage], _info: AgentInfo) -> Mode
15571557
text = '{"city": "Mexico City", "country": "Mexico"}'
15581558
return ModelResponse(parts=[TextPart(content=text)])
15591559

1560-
m = FunctionModel(return_city_location, profile=ModelProfile(supports_json_schema_output=True))
1560+
m = FunctionModel(return_city_location)
15611561

15621562
class CityLocation(BaseModel):
15631563
city: str

0 commit comments

Comments
 (0)