feat(guardrails): Enrich guardrails response back to kaapi-backend with intermediate input output results - #157
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 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 |
| # A stored validator config's `stage` isn't reliable here (the same config | ||
| # can be reused as input or output); route on what the caller actually sent. |
There was a problem hiding this comment.
didnt understand this
| config = _validator_config_at(validator_configs, order - 1) | ||
|
|
||
| type_ = None | ||
| stage = Stage.Input.value |
There was a problem hiding this comment.
this might be conflicting with above comment where you said validator config's stage isn't reliable here as same can be used both as ouput and input. please take a look at it
There was a problem hiding this comment.
defensive check i.e even if the user sets input guardrails as output validator in the llm_call body, the execution continues
6db1364 to
bd89a54
Compare
2630a9e to
ec81afa
Compare
Summary
Target issue is #158
Fixed POST /guardrails/ routing to validate whichever field (input or output) the caller actually sent, instead of relying on a validator's stored stage — a stored config's stage doesn't reliably reflect what a given call is validating, which was causing input guardrails (e.g. PIIRemover) to validate empty text and fail with a generic error.
Added per-validator input_text/output_text to validator_results in the response, sourced from the guard's history, so each validator's before/after text is traceable in execution order instead of only the chain's final safe_text.
Fixed duplicate-validator-type log misattribution by matching validator configs to guard-history entries positionally instead of by alias.
Fixed a stage-default inconsistency between validator_results and the persisted ValidatorLog rows.
Added regression tests covering the stage/routing fix and the new per-validator before/after text; trimmed verbose docstrings/comments across the touched modules.
Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Notes
Please add here if any other information is required for the reviewer.