llm-guardrails
Design guardrails for an LLM feature — input validation, prompt-injection defenses, output filtering/schema validation, allow-deny policy, and human-in-the-loop gates.
- License 许可
- MIT
- 最近更新
- 2026-10-29
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- llm-guardrails
- description
- Design guardrails for an LLM feature — input validation, prompt-injection defenses, output filtering/schema validation, allow-deny policy, and human-in-the-loop gates.
02 资源文件 1
- 参考文档routing.yaml413 B
03 SKILL.md 正文
llm-guardrails
A model will be asked to do things you didn't intend and emit things you can't ship. Guardrails are the validation layer on both sides of the model — design them as code, not as prompt pleading.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
When to use
- Exposing an LLM to untrusted input (user text, retrieved docs, tool output) or letting it drive actions.
- A feature can emit unsafe, off-brand, or malformed output, or has shown prompt-injection susceptibility.
- A workflow invokes
polymath-ai:llm-guardrails.
Not this when: you are auditing an existing LLM system end-to-end for security findings — that is polymath-security:llm-security-review (this skill designs the controls that review checks for). For agent stop conditions, see polymath-ai:agent-design.
Inputs
- The data flow: where untrusted text enters, what the model can do with it, what it emits, and to whom.
- The actions the model can trigger and their blast radius.
Procedure
- Map the trust boundaries: every place untrusted text reaches the prompt (user input, RAG documents, tool results, prior turns). Retrieved/tool content is untrusted too — indirect prompt injection rides in there.
- Input guardrails: validate/normalize input; keep untrusted content in clearly delimited, lower-trust positions; never concatenate untrusted text into the system prompt. Injection detection (classifiers, phrase filters) is defense in depth — it will miss attacks. Design so that a fully hijacked model still can't do damage (step 3).
- Privilege separation: the model proposes, code authorizes. High-impact/irreversible actions go through deterministic checks and human confirmation — the model's output is never the sole authority for a mutating action. Tools run with the end user's permissions, never broader ones. Break the exfiltration triangle: private data in context + untrusted content in context + any outbound channel (web fetch, email, webhook, rendered Markdown image or link) lets an injected instruction leak data with no user click. For flows that see untrusted content, remove at least one leg — e.g. strip or proxy external image/link rendering and disable outbound tools.
- Output guardrails: validate structure (parse/schema-check JSON, reject on failure), filter for safety/PII/secrets, and constrain to an allow-list of actions rather than a deny-list where possible.
- Ground and cite where factuality matters; flag low-confidence/unsupported output instead of emitting it silently.
- Fail closed: on a guardrail trip, the safe default is refuse/escalate, not pass-through. Define the user-visible behavior on each trip.
- Log and rate-limit: record trips for monitoring; rate-limit to bound abuse and cost. Hand the adversarial test design to
polymath-security:llm-security-review.
Output
Guardrail design: support assistant (reads tickets + help center; can tag and refund tickets)
Trust boundaries
user message untrusted → delimited <user_message>, never in the system prompt
retrieved articles untrusted → delimited <document>, lower trust than instructions
ticket bodies untrusted → indirect-injection risk (customers write them)
Input controls: length cap 8k chars; strip zero-width + control chars; injection classifier (defense in depth only)
Actions (model proposes → code authorizes)
tag_ticket auto, allow-list of 12 tags, user's own permissions
refund_ticket never from model output alone → human approval token required
Exfiltration triangle: external image/link rendering disabled for answers that saw ticket text
Output controls: JSON schema validation (retry once, then refuse); PII/secret filter; no URLs outside the help-center domain
Fail closed: any trip → "I can't help with that here — I've routed this to a human agent." + ticket flagged
Logging: every trip logged with the guardrail id; rate limit 30 requests/min/user
Adversarial tests: handed to polymath-security:llm-security-review
Quality bar
- Untrusted retrieved/tool content is treated as untrusted, not just direct user input.
- The design holds even if injection succeeds: least-privilege tools, no exfiltration path for untrusted-content flows.
- No mutating action is authorized by model output alone.
- Output is schema-validated where structured; a parse failure is handled, not assumed away.
- Every guardrail trip fails closed with a defined user-visible behavior.
04 同仓库更多 Skills
runbook
Write or refresh an operational runbook for an alert/symptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.
rfc
Draft a lightweight design RFC to docs/rfcs/<slug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).
editorial-pass
Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.
architecture-review-facilitation
Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.
architecture-doc
Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).
adr
Write an Architecture Decision Record (Michael Nygard format) to docs/adrs/NNNN-<slug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).