Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pydantic_ai_slim/pydantic_ai/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,18 @@ def walk(self) -> JsonSchema:
def transform(self, schema: JsonSchema) -> JsonSchema: # noqa C901
# Remove unnecessary keys
schema.pop('title', None)
schema.pop('default', None)
schema.pop('$schema', None)
schema.pop('discriminator', None)

default = schema.get('default', _sentinel)
if default is not _sentinel:
# the "default" keyword is not allowed in strict mode, but including it makes some Ollama models behave
# better, so we keep it around when not strict
if self.strict is True:
schema.pop('default', None)
elif self.strict is None:
self.is_strict_compatible = False

if schema_ref := schema.get('$ref'):
if schema_ref == self.root_ref:
schema['$ref'] = '#'
Expand Down
11 changes: 7 additions & 4 deletions tests/models/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,10 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
'$defs': {
'MyDefaultRecursiveDc': {
'properties': {
'field': {'anyOf': [{'$ref': '#/$defs/MyDefaultRecursiveDc'}, {'type': 'null'}]}
'field': {
'anyOf': [{'$ref': '#/$defs/MyDefaultRecursiveDc'}, {'type': 'null'}],
'default': None,
}
},
'type': 'object',
},
Expand Down Expand Up @@ -947,7 +950,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
{
'$defs': {
'MyDefaultDc': {
'properties': {'x': {'type': 'integer'}},
'properties': {'x': {'default': 1, 'type': 'integer'}},
'type': 'object',
}
},
Expand Down Expand Up @@ -987,7 +990,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
{
'$defs': {
'MyDefaultDc': {
'properties': {'x': {'type': 'integer'}},
'properties': {'x': {'default': 1, 'type': 'integer'}},
'type': 'object',
}
},
Expand Down Expand Up @@ -1027,7 +1030,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
{
'$defs': {
'MyDefaultDc': {
'properties': {'x': {'type': 'integer'}},
'properties': {'x': {'default': 1, 'type': 'integer'}},
'type': 'object',
}
},
Expand Down