Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def simplify(self) -> dict[str, Any] | None:

def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None:
schema.pop("title", None)
schema.pop("default", None)
schema.pop("additionalProperties", None)
schema.pop("$schema", None)

Expand Down
27 changes: 26 additions & 1 deletion tests/test_schema_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Locations(BaseModel):
"items": {
"properties": {
"lat": {"type": types.Type.NUMBER},
"lng": {"type": types.Type.NUMBER},
"lng": {"default": 1.1, "type": types.Type.NUMBER},
},
"required": ["lat"],
"type": types.Type.OBJECT,
Expand Down Expand Up @@ -94,6 +94,7 @@ class Locations(BaseModel):
"required": ["lat", "lng"],
"type": types.Type.OBJECT,
"nullable": True,
"default": None,
}
},
"type": types.Type.OBJECT,
Expand Down Expand Up @@ -185,3 +186,27 @@ class FormattedStringFields(BaseModel):
"type": types.Type.OBJECT,
}
assert gemini_schema == expected_gemini_schema


async def test_default_is_kept():
"""Gemini's Schema has a `default` field, and a dropped default changes the call.

A tool argument the caller pre-filled is the model's only record of the value; with the
default stripped it has nothing to send, omits the argument, and the tool is invoked
without it.
"""

class Params(BaseModel):
automation_id: str = "auto-42"
version: int = 3
name: str

gemini_schema = utils._GeminiJsonSchema(Params.model_json_schema()).simplify()
assert gemini_schema is not None
assert gemini_schema["properties"] == {
"automation_id": {"default": "auto-42", "type": types.Type.STRING},
"version": {"default": 3, "type": types.Type.INTEGER},
"name": {"type": types.Type.STRING},
}
# the surviving default must still be a value Gemini accepts on its Schema
types.Schema(**gemini_schema["properties"]["automation_id"])