Shipping an AI feature safely: guardrails, fallbacks and human review

The checks, limits and UI patterns that keep an AI feature from leaking data, embarrassing your brand or breaking when the provider has a bad day.

Samed Škulj

Samed Škulj
· 3 min read

An AI feature that works in testing can still fail in production in ways normal features don't: it can be talked into ignoring its instructions, show one customer's data to another, invent facts, or simply time out. Guardrails are the set of checks that make those failures rare, visible and cheap.

Data access: the model sees only what the user may see

The most serious risk is not the model saying something odd. It's the model being given data the current user should not have.

  • Filter before the prompt. Retrieve context with the same permission checks as the rest of your app: workspace, role, record ownership. Never retrieve broadly and ask the model to "only use what the user can see".
  • Treat tool calls as API calls. If the model can call functions (search, update a record), each function must check permissions for the current user, exactly like an API endpoint.
  • Keep secrets out of prompts. API keys, internal notes and other customers' data should never be in the context.

Prompt injection: assume the input is hostile

Any text the model reads (a user message, an uploaded document, an email, a web page) may contain instructions like "ignore previous instructions and…". You can't fully prevent a model from being influenced by them. So design so it doesn't matter:

  • Give the model only the permissions the user already has.
  • Require user confirmation for any action that changes data or sends something.
  • Clearly separate instructions from untrusted content in the prompt.
  • Don't render model output as raw HTML. Escape it, and be careful with links and images that could leak data through URLs.

Output checks

Before you show or store an output, check it with code:

  • It matches the expected schema.
  • It doesn't include content it shouldn't: other customers' names, email addresses that weren't in the input, internal IDs.
  • Lengths and values are within sane ranges.
  • For drafts that go to customers, optionally run a second, cheap check for tone or policy violations.

Failed checks lead to a retry, a fallback, or a "couldn't generate this" message. Never to a silent pass.

Grounding: reduce made-up answers

  • Give the model the source material and ask it to answer only from it.
  • Ask it to say when the answer isn't in the material.
  • Show citations, and check in code that cited sources were actually in the context.

Failure handling: the provider will have bad days

  • Set timeouts on every call. Users shouldn't stare at a spinner for a minute.
  • Retry transient errors with backoff, with a cap.
  • Consider a second provider or model as a fallback for critical features.
  • When everything fails, the feature degrades: the user can still do the task by hand.

Human review where it matters

Match the review step to the risk:

Risk of a wrong output Pattern
Low (a tag, an internal summary) Apply automatically, allow easy undo
Medium (a draft reply, a filled form) Show as a draft, user confirms
High (money, legal, sending to many people) Require explicit approval, log who approved

Logging and abuse limits

Log inputs, outputs, model, prompt version and user for every call, with a retention policy that matches your privacy commitments. Add per-user rate limits, so one account can't use your feature as a free general-purpose chatbot. More on this in keeping LLM costs under control.

Put it in your evals

Add adversarial cases to your eval set: injection attempts in documents, requests for other customers' data, off-topic requests. If a guardrail regresses, you'll know before your users do.

These guardrails are part of every AI feature build I ship. If you already have an AI feature live and haven't checked it against this list, an audit will.

Written by Samed Škulj

Senior Full-Stack Engineer since 2021. I have shipped with teams at Deel, HTEC Group (for Zoox), Ministry of Programming, and now help SaaS teams add AI features and get AI-built apps ready for production. LinkedIn