From 6e44f37d548efc91de5e8facace301cc815661c6 Mon Sep 17 00:00:00 2001
From: Harshal Patil
Date: Fri, 24 Apr 2026 07:43:55 -0400
Subject: [PATCH] fix: handle raw dict output_schema in SetModelResponseTool
When output_schema is a raw dict instance (e.g.,
{"type": "object", "properties": {...}}), SetModelResponseTool sets it
as the parameter annotation directly. This crashes in
_is_builtin_primitive_or_compound because dict instances are not
hashable and the check does `annotation in dict.keys()`.
Fix: add an explicit isinstance(output_schema, dict) branch that uses
`dict` (the type) as the annotation instead of the dict instance.
Fixes #5469
---
src/google/adk/tools/set_model_response_tool.py | 11 ++++++++++-
.../tools/test_set_model_response_tool.py | 15 +++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/google/adk/tools/set_model_response_tool.py b/src/google/adk/tools/set_model_response_tool.py
index d1dc6ed55d..22605ad037 100644
--- a/src/google/adk/tools/set_model_response_tool.py
+++ b/src/google/adk/tools/set_model_response_tool.py
@@ -87,8 +87,17 @@ def set_model_response() -> str:
annotation=list[inner_type],
)
]
+ elif isinstance(output_schema, dict):
+ # Use `dict` type, not the instance — dict instances are unhashable.
+ params = [
+ inspect.Parameter(
+ 'response',
+ inspect.Parameter.KEYWORD_ONLY,
+ annotation=dict,
+ )
+ ]
else:
- # For other schema types (list[str], dict, etc.),
+ # For other schema types (list[str], Schema, GenericAlias, etc.),
# create a single parameter with the actual schema type
params = [
inspect.Parameter(
diff --git a/tests/unittests/tools/test_set_model_response_tool.py b/tests/unittests/tools/test_set_model_response_tool.py
index 89da394acc..6f2638a588 100644
--- a/tests/unittests/tools/test_set_model_response_tool.py
+++ b/tests/unittests/tools/test_set_model_response_tool.py
@@ -467,3 +467,18 @@ async def test_run_async_dict_schema():
assert result is not None
assert isinstance(result, dict)
assert result == {'a': 1, 'b': 2, 'c': 3}
+
+
+def test_tool_initialization_raw_dict_instance():
+ """Test tool initialization with a raw dict schema instance."""
+ raw_schema = {'type': 'object', 'properties': {'name': {'type': 'string'}}}
+ tool = SetModelResponseTool(raw_schema)
+
+ assert tool.output_schema == raw_schema
+ assert not tool._is_basemodel
+ assert not tool._is_list_of_basemodel
+
+ sig = inspect.signature(tool.func)
+ assert 'response' in sig.parameters
+ assert len(sig.parameters) == 1
+ assert sig.parameters['response'].annotation is dict