refactor(guardrail): migrate guardrail consumers to typed GuardrailClient - #1488
Conversation
9192398 to
cd7504e
Compare
2070a49 to
c8aeb8a
Compare
…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>
cd7504e to
a88925e
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughGuardrail models now define typed check requests and responses. End-to-end and agentic tests use ChangesGuardrail API migration
Suggested reviewers: Merge Risk: ⚪ Minimal · up to 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)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
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>
Summary
Migrate guardrail API call sites from
sdk.guardrail.*(Stainless SDK) toclient_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(...)tocheck_guardrail(body=GuardrailCheckRequest(...)).data()guardrail.configs.list/retrievetolist_guardrail_configs/get_guardrail_config,guardrail.checktocheck_guardrailwithGuardrailCheckRequestbody +.data()Type of Change
Quality Gates
Verification
Signed-off-by:traileruv run pre-commit run -apasses, or any blocked checks are identified belowTargeted validation:
py_compileon all 5 files: compile OKuv run ruff check: all checks pass (3 auto-fixed)uv run ruff format: 4 files reformattedSummary by CodeRabbit
New Features
Refactor