Skip to content

System prompt silently dropped when sent as a string#421

Closed
dcrdev wants to merge 2 commits intorouter-for-me:mainfrom
dcrdev:main
Closed

System prompt silently dropped when sent as a string#421
dcrdev wants to merge 2 commits intorouter-for-me:mainfrom
dcrdev:main

Conversation

@dcrdev
Copy link

@dcrdev dcrdev commented Mar 8, 2026

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 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","text":""}`
    partJSON, _ = sjson.Set(partJSON, "text", system.String())
    partJSON, _ = sjson.Set(partJSON, "cache_control.type", "ephemeral")
    result += "," + partJSON
}

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

@gemini-code-assist
Copy link

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

  • System Prompt Handling: Previously, the CLIProxyAPIPlus would silently drop system prompts sent as a plain string (instead of an array of content blocks) when processing requests from Claude clients in default cloaking mode.
  • API Specification Compliance: The fix ensures compliance with the Anthropic API specification, which allows system prompts to be provided as either a plain string or an array of content blocks.
  • Data Integrity: Implemented logic to convert string-formatted system prompts into the expected content block format, preventing the loss of critical instructions, user-configured rules, and project context for AI models.

🧠 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 a conditional block to handle system fields that are plain strings, converting them into a content block format.
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

@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 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>
@luispater
Copy link

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.

@luispater luispater closed this Mar 9, 2026
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.

2 participants