Skip to content

Commit a854960

Browse files
lionpelouxclaude
andcommitted
Add sanitization to auto-generated output tool name
From #2929 We ensure that auto-generated tool output names are properly sanitized so they conform to `[a-zA-Z0-9-_]`. All characters not in this pattern will simply be ignored/skipped in the final name. The error was first remarked when using generic classes as `output_type`, where brackets in the tool name would be rejected by the provider API. Added snapshot test to verify the sanitized tool names are generated correctly from generic types like Result[StringData] and Result[int]. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3099d13 commit a854960

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

tests/test_agent.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,8 @@ class StringData(BaseModel):
665665
assert m.last_model_request_parameters.output_tools is not None
666666
assert len(m.last_model_request_parameters.output_tools) == 2
667667

668-
# Check that tool names don't contain brackets
669668
tool_names = [tool.name for tool in m.last_model_request_parameters.output_tools]
670-
for tool_name in tool_names:
671-
assert '[' not in tool_name, f"Tool name '{tool_name}' contains brackets"
672-
assert ']' not in tool_name, f"Tool name '{tool_name}' contains brackets"
673-
# Verify the name follows the pattern [a-zA-Z0-9_-]
674-
assert re.match(r'^[a-zA-Z0-9_-]+$', tool_name), f"Tool name '{tool_name}' contains invalid characters"
669+
assert tool_names == snapshot(['final_result_ResultStringData', 'final_result_Resultint'])
675670

676671

677672
def test_output_type_with_two_descriptions():

0 commit comments

Comments
 (0)