Skip to content

refactor(guardrail): migrate guardrail consumers to typed GuardrailClient - #1488

Merged
maxdubrinsky merged 3 commits into
mainfrom
aircore-827-migrate-guardrail/mdubrinsky
Aug 27, 2026
Merged

refactor(guardrail): migrate guardrail consumers to typed GuardrailClient#1488
maxdubrinsky merged 3 commits into
mainfrom
aircore-827-migrate-guardrail/mdubrinsky

Conversation

@maxdubrinsky

@maxdubrinsky maxdubrinsky commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrate guardrail API call sites from sdk.guardrail.* (Stainless SDK) to client_from_platform(sdk, GuardrailClient).* (typed HTTP client), following the pattern established in #1277.

Related Issue

AIRCORE-827

Changes

  • e2e/guardrails/test_checks.py: guardrail.check(...) to check_guardrail(body=GuardrailCheckRequest(...)).data()
  • 4 agentic-use test files: guardrail.configs.list/retrieve to list_guardrail_configs/get_guardrail_config, guardrail.check to check_guardrail with GuardrailCheckRequest body + .data()

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with documentation updates
  • Documentation only
  • Contributor tooling or automation
  • CI, build, or test infrastructure

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification: same API calls, different client
  • Tests not applicable — justification:
  • Documentation updated for user-visible behavior
  • Documentation not applicable — justification: internal refactoring

Verification

  • Pull request title follows the repository's Conventional Commit format
  • Every commit includes an appropriate Signed-off-by: trailer
  • uv run pre-commit run -a passes, or any blocked checks are identified below
  • Targeted tests pass, or tests are marked not applicable above
  • No secrets, API keys, or credentials are included

Targeted validation:

  • py_compile on all 5 files: compile OK
  • uv run ruff check: all checks pass (3 auto-fixed)
  • uv run ruff format: 4 files reformatted
  • DCO audit: 1 commit, sign-off matches author email

Summary by CodeRabbit

  • New Features

    • Added detailed guardrail check results, including overall status, individual rail statuses, activated rails, generation logs, and guardrail output.
    • Expanded guardrail checks with model, message, guardrail, and sampling options.
  • Refactor

    • Updated guardrail validation to use the current client interface.
    • Standardized configuration retrieval and content-check requests.
    • Preserved existing validation scenarios and expected results.

@maxdubrinsky
maxdubrinsky changed the base branch from mdubrinsky/aircore-1058-add-typed-clients-for-remaining-service-areas-nemoclient to aircore-827-migrate-projects/mdubrinsky August 24, 2026 17:52
@maxdubrinsky
maxdubrinsky changed the base branch from aircore-827-migrate-projects/mdubrinsky to mdubrinsky/aircore-1058-add-typed-clients-for-remaining-service-areas-nemoclient August 24, 2026 17:53
@maxdubrinsky
maxdubrinsky marked this pull request as ready for review August 24, 2026 18:24
@maxdubrinsky
maxdubrinsky requested review from a team as code owners August 24, 2026 18:24
@maxdubrinsky
maxdubrinsky force-pushed the aircore-827-migrate-guardrail/mdubrinsky branch from 9192398 to cd7504e Compare August 24, 2026 18:35
@maxdubrinsky
maxdubrinsky marked this pull request as draft August 24, 2026 18:38
@maxdubrinsky
maxdubrinsky marked this pull request as ready for review August 24, 2026 18:39
Comment thread tests/agentic-use/guardrails-content-safety-cli/tests/test_outputs.py Outdated
@maxdubrinsky
maxdubrinsky force-pushed the mdubrinsky/aircore-1058-add-typed-clients-for-remaining-service-areas-nemoclient branch from 2070a49 to c8aeb8a Compare August 25, 2026 16:35
Base automatically changed from mdubrinsky/aircore-1058-add-typed-clients-for-remaining-service-areas-nemoclient to main August 25, 2026 20:56
…ient

Migrate guardrail API call sites from sdk.guardrail.* (Stainless SDK)
to client_from_platform(sdk, GuardrailClient).* (typed HTTP client),
following the pattern established in #1277.

AIRCORE-827

Signed-off-by: Max Dubrinsky <mdubrinsky@nvidia.com>
@maxdubrinsky
maxdubrinsky force-pushed the aircore-827-migrate-guardrail/mdubrinsky branch from cd7504e to a88925e Compare August 25, 2026 21:48
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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: c35beaf6-5b44-4e10-a9a9-27f29766936f

📥 Commits

Reviewing files that changed from the base of the PR and between 196df8e and 55f1122.

📒 Files selected for processing (1)
  • e2e/guardrails/test_checks.py

Included review availability: Your plan provides up to 12 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Guardrail models now define typed check requests and responses. End-to-end and agentic tests use GuardrailClient directly for configuration access and guardrail checks. SDK-specific aliases, casts, platform adapters, and legacy nested calls were removed.

Changes

Guardrail API migration

Layer / File(s) Summary
Typed guardrail contracts
packages/nemo_platform_plugin/src/nemo_platform_plugin/guardrail/types.py
Guardrail request and response models now include model inputs, messages, options, rail statuses, and guardrail output data.
End-to-end check migration
e2e/guardrails/test_checks.py
The helper uses plugin-native request and response types. It no longer uses SDK-specific aliases or casts. Unknown configuration checks now expect BadRequestError.
Content safety test migration
tests/agentic-use/guardrails-content-safety-cli-easy/tests/test_outputs.py, tests/agentic-use/guardrails-content-safety-cli/tests/test_outputs.py
Fixtures and tests now use direct GuardrailClient methods, dictionary-based configuration data, and typed check requests.
Custom configuration test migration
tests/agentic-use/guardrails-custom-config-cli-easy/tests/test_outputs.py, tests/agentic-use/guardrails-custom-config-cli/tests/test_outputs.py
Configuration retrieval and inference checks now use direct typed guardrail client methods. Existing status assertions remain unchanged.

Suggested reviewers: a2bondar

Merge Risk: ⚪ Minimal · up to 55f11

This refactor migrates guardrail call sites to the typed client without changing the intended API behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 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 and concisely summarizes the main change: migrating guardrail consumers to the typed GuardrailClient.
Docstring Coverage ✅ Passed Docstring coverage is 81.08% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 37 functions across 6 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aircore-827-migrate-guardrail/mdubrinsky

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

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 35429/45223 78.3% 62.8%
Integration Tests 21126/42998 49.1% 22.4%

The migrated GuardrailCheckRequest and GuardrailCheckResponse were empty
extra="allow" models, so ty rejected every keyword argument at the call
sites and the lint-python-types gate failed. Declare the actual HTTP
contract instead.

Also fix consumers that the ty exclusion for tests/agentic-use hid:
list_guardrail_configs returns a paginated response with no data(), and
GuardrailConfig.data is a plain dict rather than a typed model, so
attribute access silently returned empty strings.

Signed-off-by: Max Dubrinsky <mdubrinsky@nvidia.com>
…on test

test_checks_rejects_unknown_config_id still expected the pre-migration
Stainless nemo_platform.APIStatusError, but _post_check now goes through
the typed GuardrailClient, which raises nemo_platform_plugin's
BadRequestError on a 400. pytest.raises therefore never matched and the
test failed despite correct server behavior. Catch BadRequestError (the
narrow 400 class) and keep the status_code == 400 assertion.

Signed-off-by: Max Dubrinsky <mdubrinsky@nvidia.com>
@maxdubrinsky
maxdubrinsky added this pull request to the merge queue Aug 27, 2026
Merged via the queue into main with commit e3f166c Aug 27, 2026
110 of 111 checks passed
@maxdubrinsky
maxdubrinsky deleted the aircore-827-migrate-guardrail/mdubrinsky branch August 27, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants