Home / Insights / Generative AI and LLMs
Generative AI and LLMs
Guardrails for Generative AI: Designing Input Filtering, Output Checks and Policy Enforcement
Guardrails are the controls that sit around a generative model and decide what goes in, what comes out and what the system is allowed to do. Done well, they are a layered design driven by a written policy, not a single moderation call. This guide explains how to design, choose and tune them.
Key takeaways
- Write the policy before choosing tools: what the assistant may discuss, which data it may reveal, which actions need approval and what happens when a rule is triggered.
- Use layers: input controls, constrained generation, output checks and action authorisation. No single filter catches everything, and models should never be the only enforcement point.
- Managed guardrail services, open safety classifiers, guardrail frameworks and custom rules each fit different needs; most production systems combine at least two.
- Every guardrail has a false-positive cost. Measure block rates and misses on an evaluation set, budget the latency, and tune thresholds per use case.
- Treat guardrails as a living system with monitoring, red teaming, incident response and change control, in line with frameworks such as NIST’s Generative AI Profile.
On this page
- What are guardrails, and where do they sit in the architecture?
- How do you turn a policy into enforceable rules?
- What should input controls check?
- What should output checks and action controls verify?
- Which guardrail tools should you use: managed, open-source or custom?
- How do you tune guardrails without blocking legitimate users?
- How do you operate guardrails over time?
- Frequently asked questions
- Sources and methodology
Once a generative AI feature reaches real users, it receives inputs nobody designed for: attempts to extract the system prompt, personal data pasted into a chat box, documents containing hidden instructions, and questions far outside the product’s purpose. It also produces outputs that can be wrong, off-brand, unsafe or simply in the wrong format for the next system. Guardrails are how a product handles both directions predictably.
This article is for CTOs, product owners and risk or compliance leads who need generative AI features to behave within defined limits. It covers how to turn a policy into controls, what to check on input and output, how to enforce rules around tools and actions, which kinds of guardrail tooling exist, and how to tune and operate them without frustrating legitimate users. It closes with a launch checklist.
Security-specific threats such as prompt injection are part of this picture, and we reference the OWASP guidance where relevant. Guardrails also cover quality, brand, privacy and scope, which is where most day-to-day enforcement actually happens.
What are guardrails, and where do they sit in the architecture?
A guardrail is any control outside the model’s own training that constrains what the system accepts, produces or does. The distinction matters. Model providers align their models during training, but your product’s rules, such as which topics are in scope, which customer data may be shown or which refunds an assistant may offer, are not known to the model. The NeMo Guardrails paper describes this as adding programmable rails at runtime, independent of the underlying model, rather than relying only on alignment embedded during training.
Four layers
- Input controls inspect and transform what reaches the model: validation, redaction, classification and injection detection.
- Constrained generation shapes what the model is likely to produce: system instructions, retrieval limited to approved sources, structured output schemas and restricted tool lists.
- Output checks inspect what the model produced before anyone sees or uses it: format validation, content classification, grounding checks and data-leak detection.
- Action authorisation decides whether a proposed tool call or side effect may run, using permissions and approvals enforced in code.
The principle that ties these together is that the model is never the only enforcement point. Instructions in a system prompt reduce the chance of unwanted behaviour, but they can be bypassed. Anything that must not happen, such as revealing another customer’s data or issuing an unapproved payment, needs a deterministic control outside the model.
Action: draw your current request flow and mark where each of the four layers exists today. Gaps in output checks and action authorisation are the most common.
How do you turn a policy into enforceable rules?
Teams often start by asking which guardrail product to buy. The better starting point is a short written policy that states what the system should and should not do. Without it, filters are configured by guesswork and nobody can say whether a block was correct.
NIST’s Generative AI Profile (NIST AI 600-1), published in July 2024, lists twelve risk categories for generative AI, including confabulation, dangerous or hateful content, data privacy, harmful bias, information integrity, information security and intellectual property. Among its suggested actions are defining acceptable use policies with criteria for queries a system should refuse, and setting minimum performance thresholds as go or no-go criteria for deployment. That gives a useful structure for a product-level policy.
| Policy area | Example rule | Enforcement layer | When triggered |
|---|---|---|---|
| Scope | Only answer questions about our products and the customer’s own account | Input topic classifier, system instructions | Polite refusal with a pointer to the right channel |
| Privacy | Never display payment card numbers or other customers’ data | Input redaction, output PII detection, data access in code | Mask value, log event |
| Accuracy | Answers about policy terms must cite an approved source | Retrieval restriction, grounding check | Replace with fallback answer or escalate |
| Safety and conduct | No hateful, sexual or violent content | Content classifier on input and output | Block and log |
| Actions | Refunds above a set amount need human approval | Tool authorisation in code | Create approval task |
| Brand | No competitor comparisons or pricing promises | Denied topics, output check | Regenerate or refuse |
Define the response, not just the block
For each rule, decide what the user sees. A blunt error message after a false positive damages trust more than most teams expect. Good responses explain what the assistant can help with, offer an alternative route, or hand over to a person.
Action: hold a one-hour workshop with product, legal or compliance and support leads to agree the first version of the policy table, then assign an owner to each row.
What should input controls check?
Input controls reduce risk before any tokens are spent on generation. Typical checks, in the order they usually run:
- Basic validation. Length limits, file types, rate limits per user and rejection of obviously malformed requests.
- Sensitive data redaction. Detect and mask personal data such as card numbers, identity numbers and contact details before the text reaches a third-party model or logs.
- Scope and topic classification. Decide whether the request is within the product’s purpose. A small classifier or rules can handle most cases quickly.
- Harmful content classification. Screen for categories your policy prohibits.
- Prompt injection detection. Look for attempts to override instructions, both in what the user types and in content the system retrieves.
Treat retrieved content as untrusted
The OWASP Top 10 for LLM Applications 2025 distinguishes direct prompt injection, where a user’s input alters model behaviour, from indirect injection, where external content such as websites or files does so. Its mitigations include constraining model behaviour, defining and validating output formats, input and output filtering, least privilege, human approval for high-risk actions, clearly segregating external content and regular adversarial testing. In practice, this means marking retrieved documents and tool results as data in the prompt, never as instructions, and assuming that some of them will contain text designed to manipulate the model.
Detection of injection is probabilistic and will miss some attempts. That is why OWASP’s list pairs filtering with least privilege and human approval: the goal is to limit what a successful injection can achieve, not to assume it will always be caught.
What should output checks and action controls verify?
Output checks are where many teams under-invest, yet they protect against the widest range of failures, including the model’s own mistakes.
Checks to consider
- Format and schema validation. If downstream code expects JSON with specific fields, validate it deterministically and retry or fail safely when it does not match.
- Grounding checks. For retrieval-based answers, verify that claims are supported by the retrieved sources. OWASP refers to evaluating context relevance, groundedness and answer relevance as the RAG Triad.
- Content classification. Run the same prohibited-content categories on outputs as on inputs.
- Data leakage. Detect personal data, secrets, internal identifiers or system prompt fragments in responses.
- Business rule checks. Prices, dates, eligibility statements and URLs can be checked against systems of record.
- Brand and tone. Banned phrases, competitor names and unapproved promises can be caught with word lists and lightweight classifiers.
Action authorisation
When a model can call tools, every call should pass through code that checks the user’s permissions, validates parameters and applies limits. High-impact actions, such as sending external messages, changing records or moving money, should require explicit approval. The model proposes; the application decides.
Streaming complicates output checks
Streaming tokens to the user improves perceived speed but means content is shown before a full check can run. Options include buffering by sentence or paragraph and checking each chunk, streaming only low-risk use cases, or showing a draft state until the final check passes. Choose per use case based on risk.
For outputs where automated checks are not enough, a human review step is the final layer; our guide to designing human review for generative AI output covers risk tiers and review queues.
Which guardrail tools should you use: managed, open-source or custom?
Guardrail tooling falls into four groups. Most production systems combine two or more.
Managed guardrail services
Cloud platforms offer configurable guardrails that work across models. Amazon Bedrock Guardrails, for example, provides content filters (including a prompt attack category), denied topics, word filters, sensitive information filters that block or mask personal data, contextual grounding checks for hallucination detection, and automated reasoning checks against logical rules. Its ApplyGuardrail API can evaluate text without invoking a model, so the same policy can be applied to any model.
Open safety classifiers
Open models trained to classify prompts and responses against a safety taxonomy can be self-hosted. The Llama Guard paper (Inan et al., 2023) describes an LLM-based safeguard that classifies both user prompts and model responses against a customisable risk taxonomy, with weights released publicly. Self-hosting keeps data in your environment but adds hosting and evaluation work.
Guardrail frameworks
Frameworks such as NeMo Guardrails let you define programmable rails, for example keeping conversations on a predefined path or away from certain topics, and orchestrate checks around model calls.
Custom rules and classifiers
Regular expressions, allow and deny lists, schema validators and small task-specific classifiers are cheap, fast and transparent. They handle many business rules better than any general tool.
| Option | Strengths | Limitations | Good fit |
|---|---|---|---|
| Managed service | Fast to configure, maintained by provider, broad coverage | Per-request cost, data leaves your boundary, less control over models | Teams already on that cloud needing broad baseline coverage |
| Open safety classifier | Self-hosted, customisable taxonomy | Hosting, latency and evaluation effort | Data residency requirements, high volume |
| Guardrail framework | Dialogue control, orchestration of many checks | Learning curve, another dependency | Conversational products with complex flows |
| Custom rules | Precise, fast, explainable, cheap | Narrow; do not generalise to new phrasing | Business rules, formats, known terms |
Action: map each row of your policy table to the cheapest tool that enforces it reliably. Use general classifiers for open-ended categories and code for anything precise.
How do you tune guardrails without blocking legitimate users?
Every filter makes two kinds of error: blocking legitimate requests (false positives) and letting through prohibited ones (false negatives). Strict settings reduce misses but frustrate users and support teams; loose settings do the opposite. The right balance differs by use case. A children’s learning app and an internal engineering assistant should not share thresholds.
Build an evaluation set for guardrails
- Real, anonymised user requests that should pass, including awkward but legitimate ones.
- Examples that should be blocked for each policy row.
- Known jailbreak and injection patterns, plus indirect injections hidden in documents.
- Borderline cases agreed with policy owners, with the expected decision written down.
Measure what matters
- Block rate and false-positive rate on legitimate traffic.
- Miss rate on prohibited examples, per category.
- Added latency per layer at p50 and p95.
- Cost per request of guardrail calls.
Budget latency deliberately
Each layer adds time. Run independent input checks in parallel, use fast rules before slower model-based classifiers, and reserve heavy checks such as grounding verification for responses where accuracy matters most.
Red team regularly
NIST AI 600-1 suggests regular testing for ways safety measures can be circumvented, red teaming against prompt injection and similar attacks, and verifying that fine-tuning does not weaken safety controls. Schedule red-team exercises before launch and after significant model or prompt changes, and add every finding to the evaluation set.
For example, a 60-person B2B software company launching a customer help assistant might start with moderate content filters, strict PII masking, a scope classifier and a grounding check on answers about contract terms. After two weeks of monitoring, it could relax the scope classifier for product-adjacent questions that were being wrongly refused, while keeping PII and grounding rules unchanged.
How do you operate guardrails over time?
Guardrails drift as models, prompts, users and threats change. Treat them as production infrastructure with owners, monitoring and change control.
Monitoring and incident response
- Log every guardrail decision with the rule triggered, without storing redacted data in clear text.
- Dashboard block rates by rule and alert on sudden changes, which often indicate a broken prompt, a new attack pattern or a model update.
- Sample blocked and allowed traffic for human review each week.
- Define incident severity levels and a response plan, including how to disable a feature quickly. NIST AI 600-1 recommends maintaining incident response plans, after-action reviews and a plan to halt deployment of a system that poses unacceptable risk.
Change control
Version guardrail configurations alongside prompts and code. Run the guardrail evaluation set in continuous integration so a threshold change or new model version cannot ship without evidence that block and miss rates remain acceptable.
Launch checklist
- Written policy table with an owner per rule and defined user-facing responses.
- Input validation, PII redaction, scope and content classification in place.
- Retrieved and tool content segregated and treated as untrusted.
- Output schema validation, content checks and data-leak detection active.
- Grounding checks on answers that must be supported by sources.
- Tool calls authorised in code; high-impact actions require approval.
- Guardrail evaluation set with agreed go or no-go thresholds.
- Latency and cost of guardrails measured and within budget.
- Monitoring, weekly sampling, red-team schedule and incident plan agreed.
Our generative AI development team includes evaluation and guardrails as part of every build: test sets, output checks and filters that keep quality stable as prompts and models change. If your assistant depends on company knowledge, our explainer on RAG versus fine-tuning covers how source grounding is set up in the first place.
Frequently asked questions
Are the safety features built into commercial models enough?
They help with broadly harmful content, but they do not know your product’s rules: which topics are in scope, which data a user may see, or which actions need approval. Those rules need guardrails you configure and enforce, ideally outside the model.
Do guardrails stop prompt injection completely?
No. Detection is probabilistic and new techniques appear regularly. OWASP’s guidance combines filtering with least privilege, segregation of external content, output validation and human approval for high-risk actions, so that a successful injection has limited impact.
How much latency do guardrails add?
It depends on the layers used. Rules and regular expressions add very little; model-based classifiers and grounding checks add more. Running independent checks in parallel, using fast rules first and reserving heavy checks for high-risk responses keeps the overhead manageable. Measure it at p95 on your own traffic.
Should we use a managed guardrail service or build our own?
Most teams combine both. A managed service or open safety classifier gives broad coverage of harmful content and personal data, while custom code enforces precise business rules, permissions and formats. Data residency, volume and the cloud you already use usually decide the managed component.
Who should own guardrail policy?
Policy rules need business owners, typically product with input from legal, compliance and support, while engineering owns implementation and monitoring. Assign an owner to each rule so threshold changes and disputed blocks have someone accountable for the decision.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- OWASP Gen AI Security Project: LLM01:2025 Prompt Injection — accessed 9 November 2026. Supports the direct and indirect injection definitions, the listed mitigations and the RAG Triad reference.
- NIST: AI 600-1, Generative Artificial Intelligence Profile (July 2024) — accessed 9 November 2026. Supports the twelve risk categories, acceptable use and go or no-go suggestions, red teaming and incident response actions.
- AWS: Amazon Bedrock Guardrails user guide — accessed 9 November 2026. Supports the list of managed safeguard types and the ApplyGuardrail API for model-independent checks.
- Inan et al.: Llama Guard, LLM-based Input-Output Safeguard for Human-AI Conversations (arXiv, 2023) — accessed 9 November 2026. Supports the description of an open safety classifier for prompts and responses with a customisable taxonomy.
- Rebedea et al.: NeMo Guardrails, a Toolkit for Controllable and Safe LLM Applications with Programmable Rails (arXiv, 2023) — accessed 9 November 2026. Supports the description of runtime programmable rails independent of the underlying model.
Related reading
Continue your research
Would your AI feature hold up against real user traffic?
We can review your policy, input and output controls and tool permissions, then test them against an evaluation set before launch.
