fix(tools): accept dict output_schema in SetModelResponseTool (#5469)#5516
Open
MukundaKatta wants to merge 1 commit intogoogle:mainfrom
Open
fix(tools): accept dict output_schema in SetModelResponseTool (#5469)#5516MukundaKatta wants to merge 1 commit intogoogle:mainfrom
MukundaKatta wants to merge 1 commit intogoogle:mainfrom
Conversation
…#5469) When `output_schema` is a raw dict (e.g. `{"type": "object", "properties": {...}}`), `SetModelResponseTool` previously fell through to the generic else branch and used the dict instance itself as the parameter annotation. Downstream, `_function_parameter_parse_util._is_builtin_primitive_or_compound` does `annotation in _py_builtin_type_to_schema_type.keys()`, which calls `__hash__` on the annotation and raises `TypeError: unhashable type: 'dict'`. Detect raw dict schemas explicitly and use the `dict` type as the annotation, so the existing builtin lookup maps it to `Type.OBJECT` cleanly. `run_async` already handles this case via the existing pass-through branch. Fixes google#5469
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
Fixes #5469. When
output_schemais a raw dict (e.g.{"type": "object", "properties": {...}}),SetModelResponseTool.__init__previously fell through to the genericelsebranch and used the dict instance as the parameter annotation. Downstream,_function_parameter_parse_util._is_builtin_primitive_or_compounddoesannotation in _py_builtin_type_to_schema_type.keys(), which calls__hash__on the annotation and raisesTypeError: unhashable type: 'dict'.This change adds an explicit
elif isinstance(output_schema, dict)branch that uses thedicttype (hashable) as the annotation, so the existing builtin lookup maps it toType.OBJECTcleanly.run_asyncalready handles this case via the existingargs.get('response')pass-through.Reproduction (before fix)
Testing plan
tests/unittests/tools/test_set_model_response_tool.py:test_tool_initialization_raw_dict_schema—__init__with a raw dict does not crash and stores the schema.test_function_signature_generation_raw_dict_schema— generated signature has a singleresponse: dictparameter (annotation is thedicttype, not the dict instance).test_get_declaration_raw_dict_schema—_get_declaration()returns a valid declaration without raisingTypeError.test_run_async_raw_dict_schema—run_asyncreturns the response unchanged.pytest tests/unittests/tools/test_set_model_response_tool.py -qBaseModel,list[BaseModel],list[str],dict[str, int]schemas remain unchanged and still pass.Notes
list[str]/dict[str, int].