System prompt silently dropped when sent as a string#1992
System prompt silently dropped when sent as a string#1992luispater merged 2 commits intorouter-for-me:devfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue in CLIProxyAPIPlus where system prompts provided as a simple string were inadvertently discarded. The change ensures that all valid system prompt formats, including plain strings, are correctly processed and passed to the model, thereby preserving essential instructions and maintaining expected model behavior for various client configurations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a bug where the system prompt is silently dropped if it's provided as a string instead of an array of content blocks. The change correctly handles the string case by converting it into a content block. The fix is correct and addresses the issue described. I've added one comment regarding error handling for improved code robustness.
xkonjin
left a comment
There was a problem hiding this comment.
Automated review focusing on bugs, security, and test coverage.
PR: System prompt silently dropped when sent as a string (#1992)
Key observations:
- No test files changed. Consider adding or updating tests for modified code paths.
Suggestions:
- Add or update unit/integration tests for changed code paths.
- Run dependency and static security scans (pip-audit/npm audit/Semgrep) and address findings.
- Double check error handling and input validation on new code paths.
…tructionsWithMode
When using CLIProxyAPI as a proxy, any client that sends the system prompt as a plain string rather than as an array of content blocks will have its entire system prompt silently dropped. The system prompt contains all the instructions that guide how the model behaves. This affects any claude client using the default cloaking mode, since those are the requests that go through the code path where the string format isn't handled.
Problem
The
checkSystemInstructionsWithModefunction ininternal/runtime/executor/claude_executor.goonly handles thesystemfield when it is an array of content blocks. When a client sendssystemas a plain string, which is equally valid per the Anthropic API spec - the entire system prompt is silently discarded.This affects any client that:
"system": "..."(string) instead of"system": [{"type": "text", "text": "..."}](array)claude-cliUser-Agent, causingshouldCloak()to returntruein the default"auto"cloak modeIn practice this means some tools lose their entire system prompt - including user-configured rules, project context, and tool-use instructions, when routing through CLIProxyAPIPlus.
Root Cause
In
checkSystemInstructionsWithMode, the non-strict-mode path builds the newsystemarray by iterating over existing content blocks:When
systemis a plain JSON string,system.IsArray()isfalse, so the user's system prompt is never appended. The field is then overwritten with only[billingBlock, agentBlock].Fix
Handle the string case by converting it into a content block before appending, consistent with how array elements are already handled:
Array-format requests continue to work identically and are unaffected by this change.
Fixes: #1994