Skip to contents

policy_controls() defines how secure_chat() should respond after a scanner has already resolved a prompt, context row, or output as blocked. Scanner reports still use the core actions allow, redact, and block; controls decide whether the orchestration layer should drop context, return a refusal message, or mark a run for human review.

Usage

policy_controls(
  on_prompt_block = "block",
  on_context_block = "drop",
  on_output_block = "block",
  refusal_message = "I can't safely complete that request.",
  escalation_message = "Human review requested by llmshieldr policy.",
  on_reviewer_error = "block",
  reviewer_timeout_seconds = NULL,
  reviewer_retries = 0L,
  show_stats = FALSE
)

Arguments

on_prompt_block

One of "block", "refuse", or "escalate".

on_context_block

One of "drop", "keep_redacted", "block", "refuse", or "escalate".

on_output_block

One of "block", "refuse", or "escalate".

refusal_message

Message returned as result$output when a control maps a block to refuse.

escalation_message

Optional human-readable reason stored in policy metadata when a control maps a block to escalate.

on_reviewer_error

One of "block", "escalate", or "rules_only".

reviewer_timeout_seconds

Optional elapsed-time limit for each reviewer attempt. The underlying client must support interruption.

reviewer_retries

Number of retries after the first failed attempt.

show_stats

Show construction time and available usage metrics.

Value

A list of policy controls.

Details

Control fields:

  • on_prompt_block: applied when the user prompt is blocked before the chat call.

  • on_context_block: applied when one or more retrieved context rows are blocked. "drop" excludes blocked rows and continues. "keep_redacted" includes their redacted text. "block", "refuse", and "escalate" stop before the chat call.

  • on_output_block: applied when model output is blocked after the chat call.

  • on_reviewer_error: applied when requested semantic review fails or returns invalid findings. "block" is the default; "escalate" records a human-review outcome; "rules_only" opts into deterministic findings.

refuse returns refusal_message as the result output. escalate returns no output and records the final action as "escalate" for downstream routing.

Examples

guardrails <- policy(
  "enterprise_default",
  overrides = list(
    controls = policy_controls(
      on_prompt_block = "refuse",
      on_context_block = "drop"
    )
  )
)