Skip to content

feat(server): add reviewed LiteLLM Chat dialect - #2454

Merged
Pouyanpi merged 3 commits into
developfrom
pouyanpi/phase-d-final-20261013-litellm-dialect
Oct 19, 2026
Merged

Pouyanpi merged 3 commits into
developfrom
pouyanpi/phase-d-final-20261013-litellm-dialect

Conversation

@Pouyanpi

@Pouyanpi Pouyanpi commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds an explicitly selected LiteLLM Chat dialect for reviewed buffered and
streaming wire shapes while retaining the single-text guardrail profile.

Why

LiteLLM can add provider-specific extension fields to otherwise OpenAI-compatible
responses. Those fields need a reviewed policy so inspected exchanges can accept
supported shapes without widening the default OpenAI declaration.

How it works

Typed Python projections define the dialect. Message and choice extension
containers remain closed; null refusal, empty content arrays, and reviewed
native finish metadata have individual policies. Streaming uses rebound
projections and the existing OpenAI event semantics and lifecycle hooks.

A trusted application explicitly supplies the endpoint declaration. Omitting
it retains the default OpenAI policy. Hostnames, model strings, response fields,
and exported YAML do not select a dialect.

What Changed

  • Adds reviewed buffered message and choice extensions with closed containers.
  • Recognizes empty streaming extension bags and empty content arrays without accepting unsupported content.
  • Derives coverage, text locations, and contract export from the bound declarations.
  • Reuses the OpenAI request boundary, native errors, and per-stream lifecycle hooks.
  • Adds acceptance, rejection, original-byte preservation, and export tests.
  • Documents immutable LiteLLM source evidence and the limits of the supported subset.

Review Notes

Review the field policy and explicit selection boundary. This is a reviewed
LiteLLM subset, not compatibility with every release, backend, or gateway.
No additional request controls or arbitrary extension contents are enabled.
No LiteLLM runtime dependency or compiler machinery is introduced.

AI tools assisted with implementation and review.

Summary by CodeRabbit

  • New Features
    • Added an experimental LiteLLM chat option that can be selected explicitly when configuring the OpenAI-compatible endpoint.
    • Added support for LiteLLM request, response, and streaming formats with strict checks on accepted content. Valid provider responses are preserved, while unreviewed content is rejected.
  • Documentation
    • Documented supported formats, endpoint selection, streaming behavior, and contract export guidance.

@github-actions github-actions Bot added status: needs triage New issues that have not yet been reviewed or categorized. size: XL labels Oct 14, 2026
@Pouyanpi
Pouyanpi marked this pull request as ready for review October 14, 2026 11:52
@Pouyanpi Pouyanpi added status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile). and removed status: needs triage New issues that have not yet been reviewed or categorized. labels Oct 14, 2026
@Pouyanpi
Pouyanpi force-pushed the pouyanpi/phase-d-final-20261013-litellm-dialect branch from 3183c7f to 89a5657 Compare October 14, 2026 12:05
@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Adds an explicitly selected LiteLLM Chat dialect without changing the default OpenAI policy.

  • Applications can explicitly use LiteLLM Chat replies with guardrails.
  • LiteLLM streams keep OpenAI text checks while accepting empty extension fields.

No actionable issues were found. Tests were inspected but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Trusted application] --> B{Endpoint supplied?}
  B -->|No| C[Default OpenAI declaration]
  B -->|LiteLLM| D[Reviewed LiteLLM declaration]
  C --> E[Shared request checks]
  D --> E
  E --> F[Upstream provider]
  F --> G[Selected response or stream checks]
  G --> H[Return allowed original bytes]
Loading

Reviews (3) · Last reviewed commit: "docs(server): remove local planning deta..." · Reviewed by Greptile

@Pouyanpi
Pouyanpi requested a review from m-misiura October 19, 2026 12:44

@m-misiura m-misiura left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM :)

Base automatically changed from pouyanpi/phase-d-final-20261013-d1-outbound to develop October 19, 2026 13:46
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Support the gateway response subset needed by the next recorded-test cut without opening the base OpenAI policy or treating provider-specific content as opaque. Keep nullable extension containers closed, allow only null message refusal and empty choice extensions, and explicitly rebind nested response types.

Reuse the authoritative OpenAI request and stream bindings and add trusted endpoint selection to the private router. Export the resolved policy through the existing CLI; document pinned source evidence and the limits of the supported subset. No LiteLLM runtime dependency, dialect registry, YAML inheritance, or compiler machinery is introduced.

Validation: 625 selected offline tests, changed-file pre-commit, export CLI drift check, and Markdown link checks pass. An independent policy-level check accepts both buffered success recordings and 117 events across the two streaming recordings at D-2 commit 1607aa70a4; full recorded HTTP replay remains with D-2.
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Review LiteLLM v1.102.1 source alongside deployment OpenAPI and archived recordings instead of treating observed payloads as the entire schema. Preserve native finish metadata as opaque and recognize empty source-declared content fields and streaming extension bags without allowing unreviewed generated content.

Reuse OpenAI event roles and handwritten lifecycle hooks, derive policy from the rebound typed declarations, and regenerate the inspection contract. Document version evidence, request-control exclusions, and application-owned extensions. Validated 678 focused offline tests and pre-commit.

Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
@Pouyanpi
Pouyanpi force-pushed the pouyanpi/phase-d-final-20261013-litellm-dialect branch from 16a81b3 to 1cb60a4 Compare October 19, 2026 13:50
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA-NeMo/Guardrails/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 7326e7a9-0ce2-4584-9151-55471a7651e8
📥 Commits

Reviewing files that changed from the base of the PR and between fc75289 and 1cb60a4.

⛔ Files ignored due to path filters: 1
  • nemoguardrails/server/experimental/contracts/openai/_generated/litellm-chat-completions.guard.yaml is excluded by !**/_generated/**
📒 Files selected for processing: 8
  • nemoguardrails/server/experimental/contracts/openai/README.md
  • nemoguardrails/server/experimental/providers/openai/dialects/__init__.py
  • nemoguardrails/server/experimental/providers/openai/dialects/litellm/README.md
  • nemoguardrails/server/experimental/providers/openai/dialects/litellm/__init__.py
  • nemoguardrails/server/experimental/providers/openai/dialects/litellm/chat_completions.py
  • nemoguardrails/server/experimental/providers/openai/dialects/litellm/stream.py
  • nemoguardrails/server/experimental/providers/openai/integration.py
  • tests/server/experimental/test_litellm_chat_dialect.py
📝 Walkthrough

This change adds an experimental LiteLLM Chat dialect with constrained buffered and streaming response policies. The OpenAI router accepts an optional endpoint so applications can select the dialect explicitly. Tests cover policy validation, contract export, and router behavior.

Changes: LiteLLM Chat Dialect

Layer / File(s) Summary
Buffered response policy
nemoguardrails/server/experimental/providers/openai/dialects/litellm/chat_completions.py, nemoguardrails/server/experimental/providers/openai/dialects/litellm/README.md, tests/server/experimental/test_litellm_chat_dialect.py
Adds a guarded response projection with one choice and constrained message and choice fields. Tests check accepted empty fields, opaque metadata, and rejection of unreviewed response fields.
Streaming response policy
nemoguardrails/server/experimental/providers/openai/dialects/litellm/stream.py, tests/server/experimental/test_litellm_chat_dialect.py
Adds LiteLLM stream projections and a policy-based classifier. Tests check extension and content constraints, classifier behavior, and provider errors.
Endpoint selection and validation
nemoguardrails/server/experimental/providers/openai/integration.py, nemoguardrails/server/experimental/providers/openai/dialects/*, nemoguardrails/server/experimental/providers/openai/dialects/litellm/README.md, nemoguardrails/server/experimental/contracts/openai/README.md, tests/server/experimental/test_litellm_chat_dialect.py
Adds an optional router endpoint while retaining the OpenAI error mapping and OpenAI endpoint as the default. Tests cover explicit dialect selection, contract export, request validation, and buffered and streaming requests.

Priority: ➖ Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant OpenAIRouter as create_openai_chat_router
  participant GuardedOperation
  participant Checker as ContentChecker
  participant Dispatch as HttpDispatch
  Application->>OpenAIRouter: Supply LiteLLM endpoint
  OpenAIRouter->>GuardedOperation: Create operation with endpoint and OpenAI error mapping
  GuardedOperation->>Checker: Inspect request when inspection is enabled
  GuardedOperation->>Dispatch: Forward request
  Dispatch-->>GuardedOperation: Return provider response
  GuardedOperation->>Checker: Inspect response when inspection is enabled
Loading
Merge Risk: ⚪ Minimal · up to 1cb60

The reviewed LiteLLM dialect change is ready to merge after normal checks; no actionable merge-blocking risk remains.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 6 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 and concisely describes the main change: adding a reviewed LiteLLM Chat dialect to the server.
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.
Test Results For Major Changes Passed The PR is a major feature change: it adds a LiteLLM dialect, endpoint selection, generated contract, and 433 lines of focused tests. The PR description documents testing information, including accepta…
Full details: Test Results For Major Changes

Explanation

The PR is a major feature change: it adds a LiteLLM dialect, endpoint selection, generated contract, and 433 lines of focused tests. The PR description documents testing information, including acceptance, rejection, byte-preservation, and export tests. The supplied objectives also record 678 focused offline tests and pre-commit validation. This satisfies the check.

Full details: Docstring Coverage

Explanation

Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 6 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Pouyanpi
Pouyanpi merged commit 07859ca into develop Oct 19, 2026
21 checks passed
@Pouyanpi
Pouyanpi deleted the pouyanpi/phase-d-final-20261013-litellm-dialect branch October 19, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XL status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile). temp: guardrails-proxy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants