System prompt silently dropped when sent as a string#421
System prompt silently dropped when sent as a string#421dcrdev wants to merge 2 commits intorouter-for-me:mainfrom
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 addresses a critical issue where system prompts were being silently discarded by a proxy service under specific conditions. By enhancing the proxy's ability to correctly interpret and process system prompts, it ensures that AI models receive all necessary instructions, thereby maintaining the integrity and intended behavior of client applications. 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
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 addresses a bug where a system prompt provided as a string was being silently dropped. The fix correctly handles this by converting the string into a valid content block, ensuring user-provided system instructions are preserved and properly formatted for the Anthropic API. A security audit was performed on the changes, including the checkSystemInstructionsWithMode function and internal/runtime/executor/claude_executor.go, to identify potential injection vulnerabilities, insecure data handling, and LLM safety issues. No security vulnerabilities were identified; specifically, the use of sjson.Set prevents JSON injection. Additionally, there is a minor suggestion to improve the efficiency of JSON manipulation by reducing parsing and serialization steps.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
This project only accepts pull requests that relate to third-party provider support. Any pull requests unrelated to third-party provider support will be rejected. If you need to submit any non-third-party provider changes, please open them against the mainline repository. |
When using CLIProxyAPIPlus 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.