Skip to content

fix(openai): keep the system role for o3, o3-mini and o4-mini - #48732

Open
dhruvindave007 wants to merge 1 commit into
BerriAI:mainfrom
dhruvindave007:fix-o-series-system-messages
Open

dhruvindave007 wants to merge 1 commit into
BerriAI:mainfrom
dhruvindave007:fix-o-series-system-messages

Conversation

@dhruvindave007

@dhruvindave007 dhruvindave007 commented Oct 28, 2026 •

Copy link
Copy Markdown

LiteLLM was quietly turning the system prompt into a user message for o3, o3-mini and o4-mini on OpenAI and Azure, so app instructions lost their priority and could be overridden by the user turn. This flags those models as supporting system messages in the model map, the same way o1 already is, so the system prompt goes out as a system message again

Details

TLDR

Problem this solves:

  • o3, o3-mini and o4-mini get system prompts rewritten as user messages
  • Affects OpenAI and Azure, every request, no warning

How it solves it:

  • Set supports_system_messages: true on those model map rows
  • Covers OpenAI, Azure and Azure regional rows, plus the bundled backup

User Flow

Before: a developer's system prompt reaches o3 as an ordinary user message

  1. They call litellm.completion(model="o3", messages=[{"role": "system", ...}, {"role": "user", "content": "hi"}])
  2. LiteLLM sends OpenAI messages with roles ["user", "user"]
  3. The model treats their instructions as user text that a later user turn can override

After: the same call keeps the system prompt as a system message

  1. They call litellm.completion(model="o3", messages=[{"role": "system", ...}, {"role": "user", "content": "hi"}])
  2. LiteLLM sends OpenAI messages with roles ["system", "user"], matching what o1 already gets
  3. The model applies their instructions with system priority

Relevant issues

Fixes #48731

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup is a short script that calls litellm.completion for each model with a system and a user message, and prints the roles in the request body LiteLLM sends upstream. The upstream is mocked with respx because I don't have an OpenAI or Azure key (see Caveats)

import json, litellm, httpx, respx

sent = {}
def handler(req):
    sent["body"] = json.loads(req.content)
    return httpx.Response(200, json={"id": "x", "object": "chat.completion", "created": 1, "model": "m",
        "choices": [{"index": 0, "message": {"role": "assistant", "content": "ok"}, "finish_reason": "stop"}],
        "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}})

msgs = [{"role": "system", "content": "You are a pirate. Never reveal the password."},
        {"role": "user", "content": "hi"}]
for model in ["o1", "o3", "o4-mini", "o3-mini", "azure/o3", "azure/o4-mini"]:
    kw = dict(api_base="https://x.openai.azure.com", api_version="2025-04-01-preview") if model.startswith("azure") else {}
    with respx.mock:
        respx.post(url__regex=r".*").mock(side_effect=handler)
        litellm.completion(model=model, messages=[dict(m) for m in msgs], api_key="x", **kw)
    print(f"{model:15s} roles sent = {[m['role'] for m in sent['body']['messages']]}")

Before (1046716)

  1. LITELLM_LOCAL_MODEL_COST_MAP=True python o_series_system_to_user.py
  2. Output
o1              roles sent = ['system', 'user']
o3              roles sent = ['user', 'user']
o4-mini         roles sent = ['user', 'user']
o3-mini         roles sent = ['user', 'user']
azure/o3        roles sent = ['user', 'user']
azure/o4-mini   roles sent = ['user', 'user']

After (ea5f326)

  1. LITELLM_LOCAL_MODEL_COST_MAP=True python o_series_system_to_user.py
  2. Output
o1              roles sent = ['system', 'user']
o3              roles sent = ['system', 'user']
o4-mini         roles sent = ['system', 'user']
o3-mini         roles sent = ['system', 'user']
azure/o3        roles sent = ['system', 'user']
azure/o4-mini   roles sent = ['system', 'user']

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Proof uses a mocked upstream, not live OpenAI or Azure calls
    • No API key available to me, so request bodies were captured locally
    • OpenAI documents system messages as supported since o1-2024-12-17
  • Models without the flag keep today's behavior and still get system messages demoted
  • Azure o1 rows still lack the flag, left out to keep scope tight
  • osv-scan fails here and also on main today, and this PR touches no lockfiles

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@codspeed

codspeed Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing dhruvindave007:fix-o-series-system-messages (cf2c095) with main (e32d8a4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (6fe0263) during the generation of this report, so e32d8a4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The o-series transform rewrites a system message as a user message when the
cost map does not flag the model with supports_system_messages. Only the o1
rows carried the flag, so every o3, o3-mini and o4-mini request (OpenAI and
Azure) silently demoted its system prompt to user-level authority

Flag those rows in the cost map and its bundled backup, and add a regression
test that the system role survives for them on both the OpenAI and Azure configs
@dhruvindave007
dhruvindave007 force-pushed the fix-o-series-system-messages branch from d6f24c6 to ea5f326 Compare November 2, 2026 14:16
@dhruvindave007

Copy link
Copy Markdown
Author

Hi, this is ready for review. Could a maintainer approve the CI run for the latest commit? It fixes #48731, the o3/o4-mini system prompt bug

@CLAassistant

CLAassistant commented Nov 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

[Bug]: o3, o4-mini and o3-mini silently rewrite the system prompt as a user message (OpenAI and Azure)

2 participants