Interface GuardrailEvaluationResult

Result returned by a guardrail evaluation.

Contains the action to take and optional context about why. This result is attached to response chunk metadata for observability.

Example

// Block with explanation
const result: GuardrailEvaluationResult = {
action: GuardrailAction.BLOCK,
reason: 'Content contains prohibited material',
reasonCode: 'CONTENT_POLICY_001',
metadata: { category: 'violence', confidence: 0.95 }
};

// Sanitize PII
const result: GuardrailEvaluationResult = {
action: GuardrailAction.SANITIZE,
modifiedText: 'Contact me at [EMAIL REDACTED]',
reasonCode: 'PII_REDACTED'
};
interface GuardrailEvaluationResult {
    action: GuardrailAction;
    reason?: string;
    reasonCode?: string;
    metadata?: Record<string, unknown>;
    details?: unknown;
    modifiedText?: null | string;
}

Properties

The action AgentOS should take based on this evaluation

reason?: string

Human-readable reason for the action. May be shown to end users or logged for audit.

reasonCode?: string

Machine-readable code identifying the policy or rule triggered. Useful for analytics and automated handling.

metadata?: Record<string, unknown>

Additional metadata for analytics, audit, or debugging. Persisted in response chunk metadata.

details?: unknown

Detailed information about the evaluation (e.g., moderation scores, stack traces, matched patterns). Not shown to users.

modifiedText?: null | string

Replacement text when action is GuardrailAction.SANITIZE. For input evaluation: replaces textInput before orchestration. For output evaluation: replaces textDelta (streaming) or finalResponseText (final).