Skip to content

API Reference parrot.security.groundedness.guardrail

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.security.groundedness.guardrail

View source

GroundednessGuardrail — FLAG-only OUTPUT-stage plugin (FEAT-398 Module 3).

Wires the deterministic groundedness scorer (Modules 1-2: extract_atoms / EvidenceIndex / GroundednessScorer) into the unified guardrails infrastructure (FEAT-396) as an observer guardrail: it never transforms, masks, or blocks the response — it only scores the agent's final answer against the turn's own tool-call evidence and attaches the resulting :class:~parrot.security.groundedness.policy.GroundednessReport to AIMessage.metadata["guardrails"]["groundedness"] via the standard FLAG-report mechanism (GuardrailPipeline.run keys flag_reports by Guardrail.name — see bots/guardrails/pipeline.py).

See sdd/specs/deterministic-groundedness-scoring.spec.md §3 Module 3 (v0.2 guardrails repositioning) for the full design.

Alias EvidenceIndex

Re-exported from parrot.security.groundedness.evidence.EvidenceIndex.

Class GroundednessGuardrail

OUTPUT-stage observer guardrail scoring answers against tool evidence.

Always returns GuardrailAction.FLAG on success (or PASS if scoring itself raises) — never TRANSFORM/BLOCK — so the response text delivered to the caller is guaranteed byte-identical whether groundedness scoring is enabled or not (spec §5 scoring-only invariant).

Parameter Type Default Description
policy GroundednessPolicy | None None The scoring policy. Defaults to GroundednessPolicy().
**kwargs Any {} Accepted and ignored, for forward-compat with extra policy keys passed via guardrails=[{"name": ..., ...}].

Attributes:

Attribute Type Description
stages set
policy The active :class:GroundednessPolicy.
scorer The :class:GroundednessScorer built from policy.

Method GroundednessGuardrail.check

Score content (the agent's final answer) against tool evidence.

Builds the turn's :class:EvidenceIndex from the outgoing AIMessage carried on ctx.extras["ai_message"] (populated by AbstractBot._run_output_pipeline — the only OUTPUT-stage GuardrailContext construction site), scores content against it, and returns a FLAG result carrying the serialized report. Any exception is caught and logged — the guardrail degrades to PASS (no report) rather than failing the turn (spec §3 Module 3 non-fatal contract, mirrors security/redaction.py's scrubber failure contract).

check(content: str, ctx: GuardrailContext) -> GuardrailResult

Parameter Type Default Description
content str The agent's final answer text for this turn.
ctx GuardrailContext Call context. ctx.extras["ai_message"] carries the outgoing AIMessage (source of tool_calls and the original input prompt) when available; its absence is tolerated (treated as a turn with no tool evidence).

Returns: GuardrailResult — FLAG with the serialized GroundednessReport in report on success; PASS (no report) if scoring raised.

Alias GroundednessPolicy

Re-exported from parrot.security.groundedness.policy.GroundednessPolicy.

Alias GroundednessReport

Re-exported from parrot.security.groundedness.policy.GroundednessReport.

Alias GroundednessScorer

Re-exported from parrot.security.groundedness.scorer.GroundednessScorer.

Alias Guardrail

Re-exported from parrot.bots.guardrails.Guardrail.

Alias GuardrailAction

Re-exported from parrot.bots.guardrails.GuardrailAction.

Alias GuardrailContext

Re-exported from parrot.bots.guardrails.GuardrailContext.

Alias GuardrailResult

Re-exported from parrot.bots.guardrails.GuardrailResult.

Alias GuardrailStage

Re-exported from parrot.bots.guardrails.GuardrailStage.

Alias ToolCall

Re-exported from parrot.models.basic.ToolCall.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally