Skip to content

[#20962][fix] Accept the OpenAI safety_identifier field in Chat Completions requests - #20963

Open
Sonica-B wants to merge 2 commits into
NVIDIA:mainfrom
Sonica-B:fix/chat-safety-identifier
Open

Sonica-B wants to merge 2 commits into
NVIDIA:mainfrom
Sonica-B:fix/chat-safety-identifier

Conversation

@Sonica-B

@Sonica-B Sonica-B commented Oct 25, 2026 •

Copy link
Copy Markdown

Dev Engineer Review

ChatCompletionRequest now accepts optional safety_identifier: Optional[str] = None and otherwise ignores it. The schema continues to reject unknown fields. The API stability reference records the field as stable and optional.

QA Engineer Review

The new unit test covers string values, JSON input, the None default, invalid value types, unchanged legacy user and other dumped fields, and rejection of an unknown field. The CPU test list includes the test file. Coverage verdict: sufficient for the request-schema change. The PR reports 30 passing local tests; this result was not independently verified. No CI result is provided.

Per-File QA Perspective

  • tensorrt_llm/serve/openai_protocol.py — Verify requests with and without safety_identifier validate, and omitted values default to None. Verify the value does not affect request handling.
  • tests/unittest/llmapi/apps/test_openai_protocol_safety_identifier.py — Covers accepted and rejected inputs and checks that other request fields remain unchanged. Listed in the CPU CI test list.
  • tests/integration/test_lists/test-db/l0_cpu.yml — Adds the new unit test to the CPU CI list.
  • tests/unittest/api_stability/references/trtllm_serve_api.yaml — Records safety_identifier as a stable, optional ChatCompletionRequest field with a null default.

Description

OpenAI's Chat Completions API includes safety_identifier: a stable, hashed end-user ID that OpenAI uses for abuse detection. The OpenAI SDK documents user as "being replaced by safety_identifier and prompt_cache_key", so clients that migrate off user send safety_identifier instead. ChatCompletionRequest inherits extra="forbid" from OpenAIBaseModel and declares user but not safety_identifier, so these requests fail with 400 extra_forbidden (#20962).

This PR declares safety_identifier: Optional[str] = None next to user. Like user, it is accepted for compatibility and otherwise ignored, because the server does no end-user abuse detection. Unknown fields are still rejected, and other fields are unchanged. It is the companion of #20368 (prompt_cache_key, the other replacement for user) and follows the same pattern as #20864 (store).

Why accept and ignore it rather than act on it: the field only carries meaning for OpenAI's own abuse monitoring. Nothing in trtllm-serve keys on an end-user identity (user is ignored the same way). Prefix isolation between tenants is cache_salt's job. vLLM accepts the field (extra fields are allowed and logged as ignored); SGLang's ChatCompletionRequest uses Pydantic's default, which drops unknown fields. OpenAI caps the value at 128 characters. That limit is not enforced here, since the value is unused (it matches how user is declared).

Fixes #20962

Label request: this adds a row to trtllm_serve_api.yaml, so it should carry the api-compatible label, like #20368 and #20864. I can't set labels from a fork; could a maintainer add it?

Test Coverage

  • tests/unittest/llmapi/apps/test_openai_protocol_safety_identifier.py (new, cpu_only, registered in l0_cpu.yml): the field is accepted from kwargs and from JSON, defaults to None, rejects non-string values, leaves other fields (including user) unchanged, and unknown fields are still rejected.
  • tests/unittest/api_stability/test_serve_api.py: the new ChatCompletionRequest.safety_identifier row in references/trtllm_serve_api.yaml (kind: openai, status: stable, default null, not required).
  • Run locally on CPU (Windows, Python 3.11, pydantic 2.14.1). openai_protocol.py was imported directly, with the CUDA-dependent tensorrt_llm package __init__s stubbed, because import tensorrt_llm needs the Linux CUDA build. Results: the new test file, test_openai_protocol_{parallel_tool_calls,tools,mm_processor_kwargs}.py and test_serve_api.py gave 30 passed. Without the one-line model change, 5 of the new tests and test_yaml_fields_exist_on_live_model fail. CI is the authoritative run.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ChatCompletionRequest now accepts and ignores an optional safety_identifier string. CPU tests cover its input behavior, and the API stability reference and CPU test list include the field and tests.

Changes

Chat completion safety identifier

Layer / File(s) Summary
Request field and validation
tensorrt_llm/serve/openai_protocol.py, tests/unittest/api_stability/references/trtllm_serve_api.yaml, tests/unittest/llmapi/apps/test_openai_protocol_safety_identifier.py, tests/integration/test_lists/test-db/l0_cpu.yml
ChatCompletionRequest accepts and ignores the optional field. The API stability reference marks it as an optional string. CPU tests cover accepted and rejected values, the default, JSON input, and compatibility with user; the CPU integration list registers the tests.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested labels: api-compatible

Merge Risk: Minimal · up to 0dcad

The optional identifier is accepted without affecting generation. No merge-blocking issue is evident.

Security architecture risk: Minimal · up to 0dcad

The change accepts an optional compatibility field without giving it authentication, authorization, routing, or cache-isolation authority. No material security risk was identified. Compatibility with older workers remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The newly accepted client-controlled string can cross the existing disaggregated worker transport boundary. The inspected backend conversion paths do not give its value authority over generation settings, tenant/cache identity, or routing.

Trust Boundaries and Controls

  • observed — Disaggregated authentication signs separate disaggregation and affinity metadata, not safety_identifier. Request strictness remains enabled, and provided-field sampling metadata is filtered through a whitelist that excludes the new field.
Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title follows the repository template: a GitHub issue reference [#20962], the [fix] type, and a short summary. It names the main change, which is accepting the OpenAI safety_identifier field in Ch…
Description check Passed The description covers the purpose, the solution, and the test coverage. It explains why the field is accepted and ignored, how it relates to user, prompt_cache_key, and store, and which tests were ru…
Linked Issues check Passed [#20962] requires /v1/chat/completions to accept safety_identifier instead of returning extra_forbidden. The whole-PR diff (merge base to head 0dcade2) adds `safety_identifier: Optional[str] = N…
Out of Scope Changes check Passed The whole-PR file set maps to [#20962]. openai_protocol.py contains the single-field compatibility declaration. The new test file verifies that declaration. l0_cpu.yml registers the new test file …
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Full details: Title check

Explanation

The title follows the repository template: a GitHub issue reference [#20962], the [fix] type, and a short summary. It names the main change, which is accepting the OpenAI safety_identifier field in Chat Completions requests, and the raw summary confirms that change in ChatCompletionRequest. The title is 84 characters, which is slightly long but still clear.

Full details: Description check

Explanation

The description covers the purpose, the solution, and the test coverage. It explains why the field is accepted and ignored, how it relates to user, prompt_cache_key, and store, and which tests were run. It also records that the api-compatible label was requested. The PR checklist is marked as reviewed. The Description and Test Coverage sections match the template. The template's ticket-and-type title format is followed. The description does not mention the test-file name in the template's exact form, but the test coverage section lists the new file and its assertions.

Full details: Linked Issues check

Explanation

[#20962] requires /v1/chat/completions to accept safety_identifier instead of returning extra_forbidden. The whole-PR diff (merge base to head 0dcade2) adds safety_identifier: Optional[str] = None to ChatCompletionRequest in tensorrt_llm/serve/openai_protocol.py, next to user. The field is accepted and not used for server behavior, which matches the issue's proposed handling. The new test file tests/unittest/llmapi/apps/test_openai_protocol_safety_identifier.py checks acceptance from kwargs and JSON, the None default, rejection of non-string values, unchanged handling of user and other fields, and continued rejection of unknown fields. The API reference row in trtllm_serve_api.yaml documents the field. The issue does not require a length limit, and the 128-character cap is not enforced by design. The changes since the previous review do not alter this conclusion. No unmet coding requirement is identified.

Full details: Out of Scope Changes check

Explanation

The whole-PR file set maps to [#20962]. openai_protocol.py contains the single-field compatibility declaration. The new test file verifies that declaration. l0_cpu.yml registers the new test file for CPU runs. trtllm_serve_api.yaml adds the API reference row, and test_serve_api.py validates it against the live model. No unrelated behavior change appears in the reviewed diff. The references to #20368 and #20864 describe the pattern only and do not add their work to this PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between aec1891 and 0dcade2.

Files selected for processing: 3

  • tensorrt_llm/serve/openai_protocol.py
  • tests/integration/test_lists/test-db/l0_cpu.yml
  • tests/unittest/api_stability/references/trtllm_serve_api.yaml

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

…ions requests

OpenAI's Chat Completions API documents safety_identifier as the replacement for the deprecated user field, and OpenAI clients may set it on every request. ChatCompletionRequest is extra="forbid" and has no such field, so these requests fail validation with extra_forbidden. Declare it next to user; like user, the value is accepted and ignored.

Adds a CPU unit test, registers it in l0_cpu.yml, and records the field in the trtllm-serve API stability reference.

Signed-off-by: Sonica-B <[email protected]>
…ifier

Signed-off-by: Sonica-B <[email protected]>

# Conflicts:
#	tests/integration/test_lists/test-db/l0_cpu.yml

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

Community want to contribute PRs initiated from Community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: trtllm-serve /v1/chat/completions rejects the standard OpenAI field safety_identifier with 400

2 participants