Skip to content

feat(guardrails): Enrich guardrails response back to kaapi-backend with intermediate input output results - #157

Closed
Prajna1999 wants to merge 0 commit into
logging/sentry-otelfrom
metadata/add-more-fields
Closed

feat(guardrails): Enrich guardrails response back to kaapi-backend with intermediate input output results#157
Prajna1999 wants to merge 0 commit into
logging/sentry-otelfrom
metadata/add-more-fields

Conversation

@Prajna1999

@Prajna1999 Prajna1999 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

@Prajna1999 Prajna1999 self-assigned this Sep 9, 2026
@Prajna1999
Prajna1999 added this pull request to stack #155 September 9, 2026 06:08
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5f03fe36-c737-41df-92ac-ecfb9a7cfb7d


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.

❤️ Share

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

Comment on lines +107 to +108
# 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt understand this

config = _validator_config_at(validator_configs, order - 1)

type_ = None
stage = Stage.Input.value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defensive check i.e even if the user sets input guardrails as output validator in the llm_call body, the execution continues

@Prajna1999 Prajna1999 changed the title feat: add more fields to input/output feat(guardrails): Enrich guardrails response back to kaapi-backend with intermediate input output results Sep 9, 2026
@Prajna1999
Prajna1999 force-pushed the metadata/add-more-fields branch from 6db1364 to bd89a54 Compare September 11, 2026 09:09
@Prajna1999 Prajna1999 closed this Sep 11, 2026
@Prajna1999
Prajna1999 force-pushed the metadata/add-more-fields branch from 2630a9e to ec81afa Compare September 11, 2026 10:31
An error occurred while trying to automatically change base from logging/sentry-otel to main September 11, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants