# Tool-stage guardrails are ENFORCED, not just validated (0.10.0 HIGH #2).
#
# The agent declares a `tool`-stage guardrail that redacts any tool result
# matching an SSN pattern. Before 0.10.0 only `input`/`output`-stage
# guardrails were wired into the runtime: a `tool` (or `workflow`) stage
# guardrail passed `/specs/validate`, satisfied the production
# `require_guardrails` gate, deployed — and was then NEVER enforced. The
# fix routes `tool`-stage plans through `build_tool_guardrail_middlewares`
# into the runtime's tool-call chain via `bind_runtime(tool_middlewares=…)`.
#
# This guardrail uses `action: redact` (a realistic PII example — the
# secret-bearing tool result is rewritten before it reaches the model).
#
# 0.11.0: EVERY tool-stage action is now enforced. A *raising* action
# (`block`/escalate/human_review/retry/revise) raises `GuardrailAbort` (a
# BaseException) that escapes the SDK bridge executor's per-tool
# `except Exception` — which previously swallowed it into a recoverable result
# — and aborts the run (sync -> 422, async -> failed). So raising tool-stage
# actions are now ACCEPTED at `/specs/validate` (the 0.10.0
# `E_GUARDRAIL_ACTION_UNSUPPORTED` reject was relaxed); swap `redact` for
# `block` above for a hard stop. End-to-end block enforcement through the real
# executor is covered in tests/test_tool_stage_guardrail_wiring.py.
#
# 0.11.0: `workflow`-stage guardrails are now enforced per step too — each
# workflow step's output is checked (block aborts; redact/revise rewrite) — so
# `E_GUARDRAIL_STAGE_UNSUPPORTED` is no longer raised. Not declared here: this
# example is a single agent, not a workflow.
#
# Running end-to-end needs a provider (the agent must CHOOSE to call the
# tool), so the offline regression in tests/test_examples_e2e.py instead
# compiles this spec, confirms the guardrail is wired into the runtime, and
# exercises it on a PII-bearing tool result to prove redaction.
#
#   kneo spec validate examples/guardrails_complete.yaml   # green
#   kneo run examples/guardrails_complete.yaml \
#     --input "look up account 4021" --target agent --json   # needs a provider

version: v1

agent:
  name: support-agent
  system_prompt: >
    Answer account questions. Use the lookup_account tool to retrieve
    records. Never reveal personally identifiable information.
  model:
    provider: openai
    name: gpt-4o-mini
  strategy:
    type: simple
  runtime_preferences:
    preferred_mode: bridge
    allowed_modes: [bridge]
  tools:
    include: [lookup_account]
  guardrails:
    tool:
      - id: no-pii
        type: regex
        action: redact
        config:
          # Social-security-number shape.
          patterns: ['\d{3}-\d{2}-\d{4}']

tools:
  lookup_account:
    description: Look up an account record by query string.
    parameters:
      type: object
      properties:
        q:
          type: string
          description: Account id or name to look up.
      required: [q]
    implementation: examples.guardrail_functions.lookup_account
