Skip to content

Fold input system/developer messages into native provider system param#48

Merged
ScriptSmith merged 3 commits into
mainfrom
fix/native-system-developer-messages
Jun 7, 2026
Merged

Fold input system/developer messages into native provider system param#48
ScriptSmith merged 3 commits into
mainfrom
fix/native-system-developer-messages

Conversation

@ScriptSmith

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a correctness bug where system and developer role messages inside the Responses API input array were silently dropped for Anthropic, Bedrock, and Vertex providers. They are now folded into each provider's native system prompt field, matching what OpenAI already does. A shared convert_utils module eliminates the per-provider duplication of text-extraction helpers.

  • Core fix (3 providers): convert_responses_input_to_messages / _bedrock_messages / _vertex now accumulate system/developer message text into system_parts and merge it with the top-level instructions via join_system_parts* helpers, instead of continue-ing and losing the content entirely.
  • New shared module: src/providers/convert_utils.rs exports easy_content_text and input_content_text, replacing what would have been three sets of duplicate helpers.
  • Azure OpenAI unrelated fix: strip_gateway_fields() is now called in the Azure adapter, mirroring the existing OpenAI adapter path to prevent internal gateway fields from leaking to the upstream endpoint.

Confidence Score: 5/5

Safe to merge — the change is a straightforward correctness fix that promotes previously-dropped content into the system prompt, all three provider paths are symmetric and unit-tested.

All three provider converters follow the same well-tested pattern. The text-extraction helpers in convert_utils are simple and correct. No existing behavior is removed — only silent data loss is eliminated. The Azure strip_gateway_fields addition mirrors an already-proven pattern from the OpenAI adapter.

No files require special attention.

Important Files Changed

Filename Overview
src/providers/convert_utils.rs New shared module with two text-extraction helpers; logic is straightforward and correct, though non-text content parts (images) are silently dropped when extracting system-prompt text.
src/providers/anthropic/convert.rs System/developer messages now folded into system_parts; join_system_parts helper is clean; unit test covers instructions + System + Developer + User message ordering.
src/providers/bedrock/convert.rs Parallel implementation to Anthropic; correctly collapses all text into a single BedrockSystemContent block; test covers System but not Developer role (noted in prior review).
src/providers/vertex/convert.rs Parallel implementation; join_system_parts_vertex correctly preserves role: "user" required by Gemini's systemInstruction field; test covers System but omits Developer role.
src/providers/azure_openai/mod.rs Adds strip_gateway_fields() call to prevent internal gateway fields leaking upstream; functionally correct though unrelated to the PR title (noted in prior review).
src/providers/mod.rs Single-line addition of pub(crate) mod convert_utils; correct visibility for a crate-internal helper module.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["convert_responses_input_to_messages(input, instructions)"] --> B["Seed system_parts with instructions"]
    B --> C{input present?}
    C -- No --> Z["join_system_parts(system_parts)"]
    C -- Yes --> D{input variant}
    D -- Text --> E["Push single user message"] --> Z
    D -- Items --> F["Iterate items"]
    F --> G{item type}
    G -- "EasyMessage(System|Developer)" --> H["easy_content_text()"] --> I["Push to system_parts"] --> F
    G -- "MessageItem(System|Developer)" --> J["input_content_text()"] --> K["Push to system_parts"] --> F
    G -- "EasyMessage(User|Assistant)" --> L["Push to messages list"] --> F
    G -- "MessageItem(User)" --> M["Push to messages list"] --> F
    G -- other --> F
    Z --> N["Return (Option<SystemPrompt>, Vec<Message>)"]
    E --> N

    subgraph "convert_utils.rs"
        H
        J
    end
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/native-syst..." | Re-trigger Greptile

Comment thread src/providers/anthropic/convert.rs Outdated
Comment thread src/providers/bedrock/convert.rs
Comment thread src/providers/azure_openai/mod.rs
@ScriptSmith

Copy link
Copy Markdown
Member Author

@greptile-apps

@ScriptSmith ScriptSmith merged commit fe2988d into main Jun 7, 2026
20 checks passed
@ScriptSmith ScriptSmith deleted the fix/native-system-developer-messages branch June 7, 2026 06:17
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.

1 participant