Skip to content

fix(libsy): preserve classifier system instruction - #195

Merged
bbednarski9 merged 1 commit into
NVIDIA-NeMo:mainfrom
bbednarski9:fix/libsy-classifier-system-instruction
Jul 30, 2026
Merged

fix(libsy): preserve classifier system instruction#195
bbednarski9 merged 1 commit into
NVIDIA-NeMo:mainfrom
bbednarski9:fix/libsy-classifier-system-instruction

Conversation

@bbednarski9

@bbednarski9 bbednarski9 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

Make the libsy LLM capability classifier place its governing policy in
LlmRequest.instructions as a system InstructionBlock. Keep only the task
conversation in LlmRequest.messages, and extend the existing request-builder
test to lock in that separation.

This is a focused libsy correctness fix. It is independent of raw-stream
preservation PR #192 and does not change streaming types, translation APIs, or
Relay code.

Why

switchyard-protocol deliberately separates model instructions from ordinary
conversation messages. The classifier labeled its policy Role::System, but
inserted it into messages. On the OpenAI Chat translation path, ordinary
messages with that role are encoded as user content, so a provider received:

user: <classifier policy>
user: <task to classify>

instead of:

system: <classifier policy>
user: <task to classify>

That breaks the classifier router specifically because its judge call depends
on a library-authored policy prompt. The random router does not synthesize a
judge prompt and is unaffected.

The issue was reproduced through NeMo Relay's real Algorithm::run_stream
dispatcher against the unmodified Switchyard baseline: a provider-boundary
assertion expected the classifier policy to have role system but observed
user. Applying only this change made the same buffered and streaming process
tests pass. A real Inference Hub smoke test then completed classifier and
selected-target calls for both buffered and streaming requests.

This restores the protocol and translation invariant at the source rather than
adding a Relay-specific translation workaround. It is not presented as a
general prompt-injection mitigation.

No linked issue.

How tested

  • uv run ruff check . clean
  • uv run mypy switchyard clean
  • uv run pytest tests/ green (1,723 passed, 35 skipped)
  • Manual smoke: NeMo Relay process E2E for buffered and streaming classifier routes, followed by real Inference Hub buffered and streaming routes

Additional Rust validation:

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test -p switchyard-libsy (195 unit, 3 observability, and 4 prompt tests passed)

Checklist

  • N/A — this is a Rust-only change to an existing type.
  • N/A — no new Python public symbols.
  • Unit tests added for new components / bug fixes.
  • N/A — no customer-facing surface changed.
  • Commits signed off (Signed-off-by: Your Name <email>) per the DCO.

Notes for reviewers

The key invariant is that classifier-owned policy belongs in
LlmRequest.instructions, while the conversation being classified remains in
LlmRequest.messages. Please pay particular attention to preserving that split
as prompt-window behavior evolves.

This branch is based directly on current main and contains one commit changing
only crates/libsy/src/algorithms/llm_class.rs; it is not stacked on PR #192.

Summary by CodeRabbit

  • Bug Fixes
    • Improved capability evaluation reliability by separating system guidance from conversation content.
    • Preserved relevant message history while reducing unnecessary context passed during evaluation.
    • Updated validation coverage to ensure requests maintain the expected structure and behavior.

Signed-off-by: Bryan Bednarski <bbednarski@nvidia.com>
@bbednarski9
bbednarski9 requested a review from a team as a code owner July 30, 2026 13:30
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d34f9f64-e975-4d4f-bf41-bcf41dd0bf88

📥 Commits

Reviewing files that changed from the base of the PR and between cb30e92 and 4c4b885.

📒 Files selected for processing (1)
  • crates/libsy/src/algorithms/llm_class.rs

Walkthrough

The capability judge request now stores the system prompt in LlmRequest.instructions through InstructionBlock, keeps message history separate, and updates the structured-request test accordingly.

Changes

Capability Judge Request

Layer / File(s) Summary
Structured request construction
crates/libsy/src/algorithms/llm_class.rs
CapabilityJudge::build_request creates a dedicated system instruction and passes the selected messages separately.
Structured request test updates
crates/libsy/src/algorithms/llm_class.rs
The test verifies the instruction contents and reduced message count.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with a prompt tucked tight,
In instructions, neat and bright.
Messages hop in a separate row,
Tests count the paths they show.
Structured paws applaud tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preserving the classifier's system instruction in libsy.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

@ryan-lempka ryan-lempka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This makes sense the classifier prompt should be a proper system message. This is how the classifier worked pre-libsy. Nice catch @bbednarski9!

@bbednarski9
bbednarski9 merged commit f3ff7ff into NVIDIA-NeMo:main Jul 30, 2026
16 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.

2 participants