LCORE-3202: Wire shield into response#2234
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Should only check the last commit. This PR should land after those two previous commits. This is just a draft PR. I removed refusal_message and moderation_id from the moderation result since I think we don't need those anymore. But then, we need to dig into all the functions that use moderation result and safely modify them so the missing fields won't cause errors. i.e. |
asimurka
left a comment
There was a problem hiding this comment.
LGTM, finally we can delete old run_shield_moderation and replace it with v2 but it's ok for now
| return ShieldModerationPassedV2() | ||
|
|
||
|
|
||
| def build_shield(shield_config: ShieldConfiguration) -> AbstractSafetyCapability[Any]: |
There was a problem hiding this comment.
use object as type var here as well
Eliminates redundant stored state by deriving refusal_response from message at access time, removing the now-unnecessary create_refusal_response helper and all constructor-site arguments.
714f48f to
0237198
Compare
Introduce AbstractSafetyCapability(AbstractCapability[T]) in capabilities/base.py, requiring subclasses to implement a run() method that accepts raw text and returns ShieldModerationResult. This enables safety capabilities to be invoked outside the pydantic-ai agent lifecycle. Migrate QuestionValidity and PiiRedactionCapability to extend the new base class and implement run(): - QuestionValidity.run() delegates to model_request and maps ALLOWED/REJECTED to ShieldModerationPassed/Blocked - PiiRedactionCapability.run() applies regex redaction and returns Blocked when PII is detected Add unit tests for both run() implementations.
Add run_shield_moderation_v2 and build_shield to utils/shields.py to run shield moderation through AbstractSafetyCapability instances instead of the Llama Stack client. Update the responses endpoint to call the new function with shield configs directly. Include unit tests covering pass, block, filtering, and error handling paths.
0237198 to
b448aac
Compare
Description
Wire V2 shield moderation into the Responses API endpoint
Add run_shield_moderation_v2 and build_shield to utils/shields.py to run safety capabilities (question validity, PII redaction) from the new ShieldConfiguration model. Call the new function in the responses endpoint handler alongside the existing Llama Stack shield path.
Type of change
Tools used to create PR
Identify any AI code assistants used in this PR (for transparency and review context)
Related Tickets & Documents
Checklist before requesting a review
Testing