Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

penguiflow-guardrails

БесплатноБез исполняемых скриптовНе проверен

Add a policy-enforcement layer to a PenguiFlow ReactPlanner — pass a `guardrail_gateway` that inspects…

hurtenerот hurtener★ 27 звёзд на GitHub

Об этом скилле

PenguiFlow Guardrails

When to use

  • Enforce tool allowlists/denylists at runtime, outside the prompt.
  • Redact secrets/PII from streamed output and tool results.
  • Fail-closed gating ("STOP if the tool would touch prod").
  • HITL approval triggered by policy (PAUSE).
  • Audit-friendly policy with stable rule_ids.
  • Reliability safety net for oversized tool observations.

When NOT to use

  • Primary access control → use ToolPolicy / ToolVisibilityPolicy (see penguiflow-reactplanner-config). Guardrails are policy enforcement, not the access boundary.
  • Sandboxing untrusted code → use a real sandbox; guardrails are a control plane.
  • Content moderation product — guardrails are intentionally small and composable.
  • HITL UX patterns → use penguiflow-hitl-pause-resume (guardrails can trigger a pause; the resume contract lives there).

Hard boundaries

Guardrails are the policy enforcement layer. They don't replace tool visibility, ToolNode hardening, or sandboxing. The reliability ObservationGuardrailConfig is bundled here but is conceptually separate — it's a context-overflow safety net, not a policy decision.

Workflow

1) Wire a gateway

Guardrails are off until you pass a guardrail_gateway. The gateway holds a RuleRegistry and an async-rule inbox:

from penguiflow.planner.guardrails import GatewayConfig, GuardrailGateway, RuleRegistry
from penguiflow.steering.guard_inbox import SteeringGuardInbox

registry = RuleRegistry()
registry.register_sync(ToolAllowlistRule(...))
registry.register_async(MyDeepRule(...))

gateway = GuardrailGateway(
    registry=registry, guard_inbox=SteeringGuardInbox(),
    config=GatewayConfig(),     # defaults: mode="enforce", sync_fail_open=False, etc.
)
planner = ReactPlanner(..., guardrail_gateway=gateway, guardrail_conversation_history_turns=1)

Library defaults: mode="enforce", sync_timeout_ms=15.0, sync_parallel=True, async_enabled=True, sync_fail_open=False, async_fail_open=True. Switch mode="shadow" during rollout.

2) Roll out via shadow then enforce

  • mode="shadow" — evaluate and log; never block.
  • mode="enforce" (default) — apply STOP/PAUSE/RETRY/REDACT.

Common rollout path: ship in shadow, measure rule hit rates and false positives, then revert to enforce per rule.

3) Classify rules — RuleCost.FAST or RuleCost.DEEP

Every rule sets a cost attribute:

  • RuleCost.FAST — synchronous, runs on the request path bounded by sync_timeout_ms (15ms default). Register via registry.register_sync(rule). Use for regex/allowlist checks and deterministic logic.
  • RuleCost.DEEP — async via SteeringGuardInbox. Register via registry.register_async(rule). Use for LLM-as-judge, network checks, slow external services.

4) Pick decision actions

Rules return GuardrailDecision(action=GuardrailAction.X, rule_id=..., reason=..., severity=..., ...). Actions:

  • ALLOW — pass through.
  • REDACT — apply redactions: tuple[RedactionSpec, ...] (path-based redaction into the event payload).
  • RETRY — re-run the LLM call with RetrySpec(max_attempts=2, corrective_message=...).
  • PAUSE — pause planner with reason="approval_required"; PauseSpec(scope=Literal["run","step","tool_call"], approver_roles, prompt, timeout_s=300.0).
  • STOP — terminate with StopSpec(error_code="GUARDRAIL_STOP", user_message=..., internal_reason=...). All fields default; override what you need.

STOP is the fail-closed default for high-risk findings. REDACT for secrets. PAUSE for "human must approve". RETRY for fixable LLM mistakes.

5) Decide fail-open vs fail-closed semantics

Knob Effect Trade-off
sync_fail_open=True Sync rule timeout → ALLOW Availability favored; policy bypass on timeout
sync_fail_open=False (recommended for high-risk) Sync rule timeout → blocks (treated as STOP-like) Safety favored; possible latency outages
async_fail_open=True (typical) Async rule unavailable → ALLOW Deep checks are advisory
async_fail_open=False Async rule unavailable → block Hard dependency on the deep service

For internal-only or low-risk agents, True everywhere is fine. For external-facing high-risk agents, set sync_fail_open=False.

6) Tap the right event surfaces

event_type When it fires What you can do
llm_before Before the LLM plans Inspect user input; STOP / RETRY / PAUSE / REDACT prompt content
tool_call_start Before a tool runs Inspect tool_name, tool_args; STOP / PAUSE / RETRY
tool_call_result After a tool returns Inspect result; REDACT secrets, STOP if disallowed content surfaced
llm_stream_chunk Each streamed text chunk REDACT secrets mid-stream

Each GuardrailEvent exposes text_content, tool_name, tool_args, and payload (tool_call_id, action_seq, conversation history). Use what you need.

7) Wire the reliability observation clamp

Separate

Полный SKILL.md на GitHub

Установить penguiflow-guardrails в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

agents/openai.yamlreferences/gateway-and-decisions.mdreferences/observation-clamp.mdreferences/rules-fast-vs-deep.md

FAQ

Что делает скилл penguiflow-guardrails?

Add a policy-enforcement layer to a PenguiFlow ReactPlanner — pass a `guardrail_gateway` that inspects `llm_before`/`tool_call_start`/`tool_call_result`/`llm_stream_chunk` events and returns `GuardrailDecision`s with actions `STOP`/`PAUSE`/`RETRY`/`REDACT`/`ALLOW`, run in `shadow` or `enforce` mode, classify rules as FAST (sync, `sync_timeout_ms`) or DEEP (async, `SteeringGuardInbox`), choose `sync_fail_open` vs safety, and configure the separate `ObservationGuardrailConfig` reliability clamp that prevents context overflow on huge tool outputs. Use when a user says "add guardrails", "PII redaction", "tool denylist", "policy enforcement", "stop unsafe tool", "fail-closed", or names `GuardrailEvent`, `GuardrailDecision`, `GatewayConfig`.

Как установить скилл penguiflow-guardrails?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл penguiflow-guardrails запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить penguiflow-guardrails с