Skip to content

Conversation

@1bcMax
Copy link
Member

@1bcMax 1bcMax commented Feb 10, 2026

Summary

  • Fixes Error: string should match pattern #17: Tool IDs with invalid characters (:, ., @, /, etc.) now get sanitized to match Anthropic's required pattern ^[a-zA-Z0-9_-]+$
  • Invalid characters are replaced with underscores
  • Handles both OpenAI format (tool_calls[].id, tool_call_id) and Anthropic content blocks (tool_use.id, tool_result.tool_use_id)

Test plan

  • Build passes
  • TypeScript type check passes
  • Unit tests for sanitization logic pass
  • Manual test with a client that sends invalid tool IDs

Fixes #17. Anthropic's API requires tool_use.id to match the pattern
^[a-zA-Z0-9_-]+$ but some clients send IDs with invalid characters
(like colons, periods, etc.) which cause 400 errors.

Added sanitizeToolIds() function that:
- Validates tool IDs against Anthropic's required pattern
- Replaces invalid characters with underscores
- Handles both OpenAI format (tool_calls[].id, tool_call_id)
  and content block formats (tool_use.id, tool_result.tool_use_id)
@1bcMax 1bcMax force-pushed the feature/subscription-failover branch from 58db428 to a1b8e04 Compare February 10, 2026 20:34
@1bcMax 1bcMax merged commit 3586803 into main Feb 10, 2026
1 check failed
@1bcMax 1bcMax deleted the feature/subscription-failover branch February 10, 2026 20:43
yourtion pushed a commit to yourtion/ClawRouter that referenced this pull request Feb 11, 2026
* fix: sanitize tool IDs to match Anthropic's pattern

Fixes BlockRunAI#17. Anthropic's API requires tool_use.id to match the pattern
^[a-zA-Z0-9_-]+$ but some clients send IDs with invalid characters
(like colons, periods, etc.) which cause 400 errors.

Added sanitizeToolIds() function that:
- Validates tool IDs against Anthropic's required pattern
- Replaces invalid characters with underscores
- Handles both OpenAI format (tool_calls[].id, tool_call_id)
  and content block formats (tool_use.id, tool_result.tool_use_id)

* test: add e2e test for tool ID sanitization (issue BlockRunAI#17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: string should match pattern

1 participant