fix: handle raw dict output_schema in SetModelResponseTool#5470
Open
harche wants to merge 2 commits intogoogle:mainfrom
Open
fix: handle raw dict output_schema in SetModelResponseTool#5470harche wants to merge 2 commits intogoogle:mainfrom
harche wants to merge 2 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
Response from ADK Triaging Agent Hello @harche, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can visit https://cla.developers.google.com/ to see your current agreements or to sign a new one. This information will help reviewers to review your PR more efficiently. Thanks! |
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 google#5469
6b9b9ef to
6e44f37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TypeError: unhashable type: 'dict'when passing a rawdictinstance asoutput_schematoLlmAgentFixes #5469
Root Cause
SetModelResponseTool.__init__setsannotation=output_schema(the dict instance) as a function parameter annotation. Downstream,_is_builtin_primitive_or_compounddoesannotation in _py_builtin_type_to_schema_type.keys(), which tries to hash the dict instance and raisesTypeError.Fix
Add an
isinstance(output_schema, dict)branch that usesdict(the type, which is hashable and already in_py_builtin_type_to_schema_type) as the annotation instead of the dict instance.Test plan
test_tool_initialization_raw_dict_instancecovering the exact crash casetest_tool_initialization_dict_schema(usesdict[str, int]GenericAlias) still passes — no regression