-
Notifications
You must be signed in to change notification settings - Fork 459
fix: add tool count validation to prevent API errors when enabling many functions #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: add tool count validation to prevent API errors when enabling many functions #604
Conversation
When too many functions are enabled (e.g., all Gmail functions plus other apps), OpenAI API returns cryptic 'There was an issue with your request' errors. Changes: - Add MAX_TOOLS constant (64) based on empirical API limits - Add early validation in route handler returning 400 with clear message - Add defensive check in openai_chat_stream with logging Closes aipotheosis-labs#337
|
Someone is attempting to deploy a commit to the Proxy Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis PR introduces a conservative tool usage limit (MAX_TOOLS = 64) to prevent OpenAI API failures when excessive tools are selected. Validation is implemented at the route handler level (returns 400 HTTPException) and the prompt module level (raises ValueError with logging) to catch the issue early and return appropriate error responses. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (1)backend/**/*.py📄 CodeRabbit inference engine (CLAUDE.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 2 files
This PR fixes the 500 Internal Server Error when enabling all Gmail functions in the playground.
What changed
MAX_TOOLS = 64constant based on empirical OpenAI API limits/chatroute returning HTTP 400 with actionable messageopenai_chat_streamwith warning logWhy it failed before
OpenAI's API has undocumented limits on tool count and total token size of tool definitions. When users enable all functions for an app (Gmail has 24 functions), the request exceeds these limits and returns a cryptic "There was an issue with your request" error that surfaces as a 500.
Why this fix works
Validates tool count before making the API call. Returns a 400 with a clear message telling users to reduce selected functions. The limit of 64 is conservative - actual limit is around 128 or ~200k tokens of tool definitions.
Risk assessment
Closes #337
To make this production-safe, the remaining work is:
This is ~3-5 days.
I can own this as a short paid engagement; otherwise this PR stands on its own.
Summary by cubic
Validate tool count to prevent cryptic OpenAI errors when too many functions are enabled. Adds a conservative MAX_TOOLS=64 and returns a clear 400 with guidance; addresses #337.
Written for commit 2487903. Summary will update on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.