fix: sanitize tool schema property keys with invalid characters#54
Open
rupjae wants to merge 1 commit intotwilio-labs:mainfrom
Open
fix: sanitize tool schema property keys with invalid characters#54rupjae wants to merge 1 commit intotwilio-labs:mainfrom
rupjae wants to merge 1 commit intotwilio-labs:mainfrom
Conversation
Twilio's OpenAPI spec contains parameter names with angle brackets
(e.g., StartTime<, EndTime>) for date range filtering. These characters
are rejected by LLM tool-use APIs that validate property keys against
/^[a-zA-Z0-9_.-]{1,64}$/. Since all tools are sent with every API
request, a single invalid key causes every message to fail, completely
breaking the session.
Adds sanitizePropertyKey() that converts < to _lt, > to _gt, and strips
other invalid characters. Applied to all code paths where property keys
are set from the OpenAPI spec.
Fixes twilio-labs#53
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ayushmudgal
approved these changes
Feb 9, 2026
|
Can we please get this merged in? There's a few open issues here #58 |
|
+1 to the sentiment above 🙏 |
|
Hi @rupjae, thanks for the PR! I've approved #50 as it includes the reverse mapping needed so sanitized keys are restored before Twilio API calls (waiting on the small linter fix if that doesn't come relatively soon I'll merge as is). #50 doesn't cover nested object properties inside |
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
sanitizePropertyKey()toloadTools.tsthat converts<to_lt,>to_gt, and strips other characters not matching^[a-zA-Z0-9_.-]{1,64}$Problem
Twilio's OpenAPI spec contains 24 parameter names with angle brackets (
StartTime<,EndTime>,DateCreated<, etc.) for date range filtering. LLM tool-use APIs (e.g., Anthropic) validate property keys against^[a-zA-Z0-9_.-]{1,64}$and reject the entire request if any key is invalid.Since all tools are sent with every API request, a single invalid key causes every message to fail — completely bricking the session:
Fixes #53
Test plan
🤖 Generated with Claude Code