How to add guardrails to an LLM app

To add guardrails to an app built on a large language model (LLM), list its risks, write a policy for each, check every input, output and tool call, choose an action per policy, log verdicts and test with attacks.

Steps

  1. List the risks. Write down what must not happen in this app: a leaked customer record, a harmful answer, an agent deleting data. Start from what the app can read and do.
  2. Write policies in plain language. One rule per risk, worded as something the AI writes or does: "The assistant reveals another customer's order." See guardrail policy.
  3. Put a check at three points. On inputs before the model call, on outputs before the user sees them, and on tool calls before they run. See input and output guardrails.
  4. Choose an action per policy. Block what is dangerous, redact personal data, hold a risky tool call for approval, and flag what only needs review. See guardrail actions.
  5. Log every verdict. Record which policy fired, on what, and what was done. Incident review and tuning both depend on it.
  6. Test with attacks. Run jailbreaks and prompt injections against the whole app before launch and after each change. See how to red team an LLM.
  7. Watch false positives. Read a sample of what was blocked, and narrow or reword any policy that stops normal requests. See false positives in guardrails.

Common mistakes

  • Checking only inputs. A harmless prompt can still produce a harmful answer.
  • Putting the rules in the system prompt and stopping there. A prompt asks, and nothing enforces it.

With White Circle

Integration is one API, or middleware, that works with any model or setup and takes about five minutes. Control then enforces your plain-language policies on every input, output and tool call.

Train your own models

Post-train any Hugging Face model with Halo. Up to 4× faster than TRL