Book a free call

How to Design an AI Guardrails Architecture

An AI guardrails architecture puts checks in four layers: input, policy, output and logging, so bad requests stop before the model and bad answers never reach users.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Design an AI Guardrails Architecture
On this page

Short answer

An AI guardrails architecture is the design of the checks around an AI model: an input layer that screens requests, a policy engine that applies the rules, an output layer that checks answers, and logging that records every decision. Good designs place each check where it can act fastest, fail safely when a check is unavailable, and version every rule so a change can be rolled back.

What is an AI guardrails architecture?

An AI guardrails architecture is the design of the layers that check an AI system before and after the model runs. It sits around the model, not inside it, so the rules can change without retraining and every decision can be reviewed.

The architecture has four layers, each with one job:

LayerJobExample checks
Input layerScreens the requestPersonal data, injection, topic
Policy engineApplies the rulesRule order, version, fail mode
Output layerChecks the answerGrounding, toxicity, format
LoggingRecords decisionsBlocked requests, rule hits

Each layer can fail on its own, so the design is judged by what happens when one does. A good architecture keeps working when a check is slow or unavailable, and it makes the cost of a bypass higher than the value an attacker could gain. The AI guardrails guide explains what guardrails are and where they sit in the system.

How do you design the input layer?

You design the input layer to screen every request before the model sees it, because a request that never reaches the model cannot cause harm. The layer runs several small checks in a fixed order, and the first check that triggers decides what happens next.

Start with the checks that are cheap and certain. Remove personal data such as names, account numbers and addresses before the request reaches the model, and drop requests that match a known injection pattern, such as instructions hidden in pasted text. These checks run with simple rules, so they are fast and easy to test.

Add a topic check for the cases rules cannot catch. A small classifier can tell whether a request belongs to the topics the system serves, and route the rest to a refusal or a human. Keep the topic list short: ten topics that are tested and monitored beat fifty that nobody maintains.

Decide what happens when a check triggers. Most inputs should be refused with a short, plain message, while a few should be passed on with a warning attached for the output layer to see. Record every blocked request, so the team can see which rules fire most and fix the ones that block good requests.

How do you design the policy engine?

You design the policy engine as the place where the rules live, separate from the code that runs them. The engine reads each request and answer, evaluates the rules in order, and returns a decision: allow, refuse, or send to a human.

Order the rules by risk, and write the order down. A rule that blocks illegal advice should run before a rule that checks tone, so a dangerous request cannot slip through while a harmless one is being polished. When two rules disagree, the stricter one should win, and the decision should say which rule fired.

Version every rule. Each rule needs a name, a version number, an owner and a date, so a change can be rolled back when it blocks good requests. Test a new version on old requests first: run it over the logged requests from the last month and count how many more it would block before it goes live.

Choose the failure mode before you need it. Fail-closed means a check that cannot run blocks the request, which is safer for regulated work. Fail-open means the request passes with a warning logged, which fits low-risk systems where availability matters more. Write the choice down per check, not per system, because the right answer differs between them.

How do you design the output layer?

You design the output layer to check every answer before the user sees it, because the model can produce a plausible answer that is wrong, unsafe or off-topic. The layer runs after the model, and it can refuse, rewrite or flag the answer.

Start with grounding. Check that the answer only uses facts from the sources the system was given, and refuse or flag answers that add numbers, dates or names the sources do not contain. A grounding check catches the most common failure in support and sales assistants, where a confident invented price does real damage.

Add a toxicity and tone check for user-facing answers. The check should catch insults, threats and biased language, and it should also catch answers that are technically fine but written in a tone the brand would not use. Keep the refusal style consistent: a short, plain refusal with a next step, not a lecture.

Check the format last. An answer that must contain a reference number, a link or a disclaimer should be checked for it, and a missing piece should send the answer back for repair rather than to the user. Format checks are cheap, and they catch the errors that make a system look careless.

Where should guardrails run?

Guardrails should run where each check can act fastest and cheapest, which usually means splitting them across the client, the server and the model side. No single place fits every check.

WhereBest forWatch out for
ClientFast format and length checksCan be bypassed, never trust it alone
ServerPolicy engine, logging, personal dataAdds latency to every request
Model sideGrounding, toxicity, toneSlowest, costs the most per call

Put cheap checks early and expensive checks late. A format or length check on the client costs almost nothing, while a grounding check on the model side costs the most, so run the cheap checks first and skip the expensive ones when an early check already refused the request.

Watch the latency budget. Every check adds time, and a user waiting two seconds for an answer will leave. Measure the time each layer adds, and set a budget per layer. When the budget is exceeded, the policy engine should decide which checks to skip and log the skip, rather than letting the request time out.

How do you build a guardrails architecture in 6 steps?

Building a guardrails architecture is a design project before it is a coding project. The steps below fit into a normal development cycle and can be tested on one use case before the system grows.

  1. List the hard limits. Write the things the system must never do, such as giving legal advice or sharing customer data.
  2. Sort by risk. Rank each limit by how likely it is and how much harm it would cause, and build the top ones first.
  3. Design the four layers. Decide which checks run at input, in the policy engine, at output, and what gets logged.
  4. Choose the failure mode. Set fail-closed for regulated checks and fail-open for low-risk ones, and write the choice down.
  5. Build the evaluation set. Collect real examples of good and bad requests and answers, including the tricky cases.
  6. Ship one guardrail at a time. Add the highest-risk check first, measure its effect, then add the next.

Keep the list short. Ten guardrails that are tested and monitored beat fifty that nobody maintains. The implementation guide walks through the build sequence step by step.

Example (hypothetical): a support chatbot for a store

Example (hypothetical): an online store adds a support chatbot that answers order questions. The team lists three hard limits: never quote a price it cannot verify, never share another customer's order details, and never promise a delivery date the system does not confirm.

The input layer removes personal data from each request and drops pasted instructions that try to change the chatbot's role. The policy engine applies the three limits in order, with the price rule first. The output layer checks every answer against the order database, so an invented price or a wrong delivery date is refused before the customer sees it.

In the first month, the chatbot handles 2,000 chats. The input layer blocks 60 requests, or 3 in 100, mostly pasted instructions. The output layer refuses 40 answers, or 2 in 100, mostly invented prices. The team reviews the logs weekly and finds 10 good requests blocked by a rule that was too strict, so it narrows the rule and re-tests it on the logged requests before shipping the change.

What are the common mistakes?

The most common guardrails architecture mistakes are putting all the rules in one place, never testing a rule change, and letting the checks slow the system until users leave.

  • Rules hidden in prompts. When the limits live in the model instructions, they cannot be tested, versioned or rolled back.
  • No failure mode. A check that cannot run should have a defined answer: block or pass with a warning, decided in advance.
  • Untested rule changes. A new rule that is never run against old requests will block good requests nobody expected.
  • Checks in the wrong place. An expensive grounding check that runs before a cheap format check wastes time and money.
  • No logging. A system that does not record what it blocked cannot find the rules that are wrong.
  • Fifty unmaintained rules. Ten guardrails that are tested and monitored beat fifty that nobody owns or reviews.

Start with the three highest-risk limits, build the four layers around them, and add rules only when the logs show a gap. The best practices guide covers the operating rules that keep guardrails working in production.

Key takeaways

  • A guardrails architecture has four layers: input, policy engine, output and logging
  • Put cheap checks early and expensive checks late, and skip the rest when an early check refuses
  • Version every rule with an owner and a date, and test changes on logged requests first
  • Choose fail-closed for regulated checks and fail-open for low-risk ones, per check
  • Log every blocked request and refused answer so bad rules can be found and fixed

Frequently asked questions

What is an AI guardrails architecture?

It is the design of the checks around an AI model: an input layer that screens requests, a policy engine that applies the rules, an output layer that checks answers, and logging that records every decision. It sits around the model, not inside it, so rules can change without retraining.

What is the difference between guardrails and AI governance?

Governance covers the policies, roles and reviews for the whole AI programme, while guardrails are the technical checks that enforce those policies at run time. A governance rule that says never share customer data becomes an input check and an output check in the guardrails architecture.

Should guardrails fail open or fail closed?

It depends on the check. Fail-closed, which blocks the request when a check cannot run, fits regulated work where a wrong answer is costly. Fail-open, which passes the request with a warning logged, fits low-risk systems where availability matters more. Decide per check, not per system.

Where should guardrails run?

Split them by cost and speed. Cheap format and length checks fit the client, the policy engine and logging fit the server, and grounding and toxicity checks fit the model side. Run cheap checks first and skip expensive ones when an early check already refused.

How do you test a guardrails change?

Run the new rule over the logged requests and answers from the last month and count how many more it would block before it goes live. Keep an evaluation set of real good and bad examples, including the tricky cases, and re-run it on every change.

How many guardrails should a system have?

Start with the three highest-risk limits and add rules only when the logs show a gap. Ten guardrails that are tested, versioned and monitored beat fifty that nobody owns or reviews, and a short list is easier to keep working.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Designing guardrails for an AI product? Talk to Hertiv.

A senior engineer replies within one business day. Or see our AI Governance service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call