Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

remove uneccesary keys in google tools ai call (#6201)

Shahmir Varqha53801bc330ae
diff --git a/marimo/_ai/_convert.py b/marimo/_ai/_convert.py
index 86771f4c0a..b01e7149c7 100644
--- a/marimo/_ai/_convert.py
+++ b/marimo/_ai/_convert.py
@@ -517,7 +517,13 @@ def convert_to_google_tools(tools: list[Tool]) -> list[dict[str, Any]]:
{
"name": tool.name,
"description": tool.description,
- "parameters": tool.parameters,
+ "parameters": {
+ # Pydantic will raise validation errors if unknown keys are present
+ # So we only include necessary keys
+ "type": tool.parameters.get("type", "object"),
+ "properties": tool.parameters.get("properties", {}),
+ "required": tool.parameters.get("required", []),
+ },
}
]
}
diff --git a/tests/_ai/test_chat_convert.py b/tests/_ai/test_chat_convert.py
index 13ba500abf..b58f5857f3 100644
--- a/tests/_ai/test_chat_convert.py
+++ b/tests/_ai/test_chat_convert.py
@@ -387,17 +387,24 @@ def test_convert_to_anthropic_tools(sample_tools):
def test_convert_to_google_tools(sample_tools):
+ # Add some additional parameters in tools, it should be ignored
+ sample_tools[0].parameters["maxNumResults"] = 10
result = convert_to_google_tools(sample_tools)
- assert len(result) == 1
- assert "function_declarations" in result[0]
- assert result[0]["function_declarations"][0]["name"] == "test_tool"
- assert (
- result[0]["function_declarations"][0]["description"] == "A test tool"
- )
- assert result[0]["function_declarations"][0]["parameters"] == {
- "type": "object",
- "properties": {"x": {"type": "integer"}},
- }
+ assert result == [
+ {
+ "function_declarations": [
+ {
+ "name": "test_tool",
+ "description": "A test tool",
+ "parameters": {
+ "type": "object",
+ "properties": {"x": {"type": "integer"}},
+ "required": [],
+ },
+ }
+ ]
+ }
+ ]
def test_convert_to_ai_sdk_messages():