Skip to content

System prompt silently dropped when sent as a string#1992

Merged
luispater merged 2 commits intorouter-for-me:devfrom
dcrdev:main
Mar 9, 2026
Merged

System prompt silently dropped when sent as a string#1992
luispater merged 2 commits intorouter-for-me:devfrom
dcrdev:main

Conversation

@dcrdev
Copy link
Contributor

@dcrdev dcrdev commented Mar 9, 2026

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 checkSystemInstructionsWithMode function in internal/runtime/executor/claude_executor.go only handles the system field when it is an array of content blocks. When a client sends system as a plain string, which is equally valid per the Anthropic API spec - the entire system prompt is silently discarded.

This affects any client that:

  1. Sends "system": "..." (string) instead of "system": [{"type": "text", "text": "..."}] (array)
  2. Does not have a claude-cli User-Agent, causing shouldCloak() to return true in the default "auto" cloak mode

In 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 new system array by iterating over existing content blocks:

result := "[" + billingBlock + "," + agentBlock
if system.IsArray() {
    system.ForEach(func(_, part gjson.Result) bool {
        // ... appends each block to result
        return true
    })
}
result += "]"

When system is a plain JSON string, system.IsArray() is false, 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:

} else if system.Type == gjson.String && system.String() != "" {
    partJSON := `{"type":"text","cache_control":{"type":"ephemeral"}}`
    partJSON, _ = sjson.Set(partJSON, "text", system.String())
    result += "," + partJSON
}

Array-format requests continue to work identically and are unaffected by this change.

Fixes: #1994

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • System Prompt Handling: Fixed a bug where system prompts sent as a plain string were silently dropped by CLIProxyAPIPlus when shouldCloak() returned true, leading to models losing critical instructions.
  • String to Content Block Conversion: Implemented logic to correctly parse string-formatted system prompts by converting them into a {"type":"text"} content block, ensuring they are properly appended to the system instruction array.

🧠 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
  • internal/runtime/executor/claude_executor.go
    • Added logic to correctly parse and include system prompts provided as a plain string.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

@xkonjin xkonjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

dcrdev added a commit to dcrdev/CLIProxyAPI that referenced this pull request Mar 9, 2026
@luispater luispater changed the base branch from main to dev March 9, 2026 13:02
@luispater luispater merged commit 4cc99e7 into router-for-me:dev Mar 9, 2026
2 checks passed
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.

System prompt silently dropped when sent as a string

3 participants