Skip to content

Add model-aware system prompt transforms - #40

Merged
mitchins merged 2 commits into
mainfrom
codex/model-aware-system-prompt-transforms
Sep 12, 2026
Merged

mitchins merged 2 commits into
mainfrom
codex/model-aware-system-prompt-transforms

Conversation

@mitchins

@mitchins mitchins commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add provider-wide and exact-model system prompt transforms for text chat completions
  • support append, prepend, and replace modes with canonical model resolution
  • preserve router-owned /no_think, skip structured system content safely, and document configuration

Verification

  • pytest -q — 1070 passed, 9 skipped
  • ruff check smolrouter/ tests/unit/test_system_prompts.py
  • vulture smolrouter/ --min-confidence=80 --exclude .venv --exclude venv --exclude .conda --exclude .cache
  • git diff --check

Peer-reviewed before and after implementation by GPT-5.6-Sol.

Summary by CodeRabbit

  • New Features

    • Added configurable system-prompt transformations for OpenAI-compatible chat requests.
    • Supports appending, prepending, or replacing system prompts.
    • Supports provider-wide defaults and exact per-model overrides.
    • Preserves supported router markers and message ordering.
  • Behavior Updates

    • Transformations are skipped for audio-output requests, Responses requests, and unsupported structured messages.
    • Requests remain unchanged when transformations cannot be safely applied.
  • Documentation

    • Added configuration guidance covering supported modes, precedence, opt-out behavior, and request limitations.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-12T22:22:37.544505Z 09def22 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Essentials

Run ID: e7889326-b008-402d-b2a5-92a19e5a9715

📥 Commits

Reviewing files that changed from the base of the PR and between 09def22 and e5d678f.

📒 Files selected for processing (1)
  • pyproject.toml

Included review availability: 1 review is currently available. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.


📝 Walkthrough

Walkthrough

This change adds validated provider-wide and model-specific system prompt policies. Eligible OpenAI chat-completions requests receive immutable prompt transformations. Audio, Responses, and unsupported message inputs remain unchanged.

Changes

System prompt policy

Layer / File(s) Summary
Policy configuration and resolution
smolrouter/interfaces.py, tests/unit/test_system_prompts.py
Adds immutable configuration validation, provider-wide and exact-model coercion, override precedence, opt-out handling, and YAML coverage.
System message transformation
smolrouter/system_prompts.py, tests/unit/test_system_prompts.py
Adds append, prepend, and replace modes. The logic copies messages, preserves /no_think markers, rejects unsupported shapes, and reports skip reasons.
Chat-completions policy application
smolrouter/mediator.py, smolrouter/providers.py, tests/unit/test_system_prompts.py, README.md, pyproject.toml
Applies policies before provider dispatch, preserves caller-owned payloads, skips audio and Responses requests, updates provider error logging, documents configuration, and enables Ruff checks.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant route_request
  participant ProviderConfig
  participant transform_system_prompt_messages
  participant SelectedProvider
  Client->>route_request: submit chat-completions payload
  route_request->>ProviderConfig: resolve policy for model
  ProviderConfig-->>route_request: return policy or no policy
  route_request->>transform_system_prompt_messages: transform copied messages
  transform_system_prompt_messages-->>route_request: return transformed messages
  route_request->>SelectedProvider: dispatch request
Loading

Merge Risk: ⚪ Minimal · up to e5d67

This configuration-only change introduces no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding model-aware system prompt transforms.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 5 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/model-aware-system-prompt-transforms

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.14286% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.94%. Comparing base (7568c8f) to head (e5d678f).

Files with missing lines Patch % Lines
smolrouter/mediator.py 75.00% 4 Missing and 4 partials ⚠️
smolrouter/interfaces.py 86.66% 3 Missing and 3 partials ⚠️
smolrouter/system_prompts.py 93.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   76.82%   76.94%   +0.12%     
==========================================
  Files          38       39       +1     
  Lines       10902    11041     +139     
  Branches     1685     1720      +35     
==========================================
+ Hits         8375     8496     +121     
- Misses       1930     1939       +9     
- Partials      597      606       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@mitchins

Copy link
Copy Markdown
Owner Author

@coderabbitai review quota refreshed, review

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

@mitchins I will review the changes in #40.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mitchins
mitchins merged commit 57aa1e6 into main Sep 12, 2026
12 checks passed
@mitchins
mitchins deleted the codex/model-aware-system-prompt-transforms branch September 12, 2026 23:35
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