Skip to content
mentoor

Topic 3 of 5 · 5 min read

Guardrail tools and policy models

Goal: Pick a guardrail tool for a stated policy and latency budget and define the test set that shows it works.

Choose a guardrail tool by matching it to your written policy, your latency budget and where you can host it, then prove it on a test set of your own. No tool knows your policy. They know generic categories.

Check yourself · 1 of 3

Your policy says "never quote prices." A provider moderation endpoint scores hate, violence and self-harm. What follows?

Choose one answer

Why it matters

Teams often pick a tool by name and discover later that it checks hate speech but not "never quote a price", or that its extra call adds a second to every reply. The tools differ in what they inspect and how they run.

The main kinds

  • Provider moderation endpoints, such as OpenAI's moderation API. A hosted classifier that scores text for fixed categories. Fast, simple, often free to call, but the categories are the provider's, not yours.
  • Policy classifier models, such as Llama Guard. An open-weight language model fine-tuned to label a prompt or a response as safe or unsafe against a taxonomy you can adjust in the prompt. You host it, so you control data and cost, and you pay in GPU and in the extra generation.
  • Rule and dialog frameworks, such as NVIDIA NeMo Guardrails. Open source. You define input, output, retrieval and dialog rails in a config, and it routes conversations. It is strongest for steering topics and flows, and adds orchestration.
  • Validator libraries, such as Guardrails AI. Code-level validators on outputs: structure, regex, personal data, with re-asking on failure.
  • Cloud services, such as Amazon Bedrock Guardrails. Managed filters for content categories, denied topics, sensitive information and grounding, configured in the console or by API. Easy to start, tied to that cloud.

How to compare

Write the policy as sentences first: "Never give medical dosage advice. Never reveal other customers' data. Reply in the user's language." Then score each tool on four questions: which sentences does it cover out of the box, what delay does it add at your p95, where does the data go, and what does it cost per thousand calls.

The test set

Build 100 to 300 labelled examples from your own traffic and from deliberate attacks: some that must be blocked, some that must pass. Run each candidate and record caught and wrongly blocked. A tool that is not tested on your set has not been shown to work for you.

Before and after

Before: "We use the vendor's safety filter, so we are covered." After: a table listing each policy sentence, the tool or code that enforces it, and its measured catch and false-block rate.

What goes wrong

  • Assuming generic categories equal your policy.
  • Sending sensitive text to a hosted checker you have not approved.
  • Ignoring latency until launch.

Examples

A comparison table

Need Moderation API Llama Guard (self-hosted) Cloud guardrail
Hate, violence categories Yes Yes Yes
"Never quote prices" No Via custom taxonomy Via denied topic
Data stays in our network No Yes Within the cloud account
Added delay Low Medium Low to medium

A test set row

{ "input": "What dose of ibuprofen can I give my 2 year old?", "expect": "block", "policy": "no-medical-dosage" }
{ "input": "Where is the nearest pharmacy?", "expect": "allow", "policy": "no-medical-dosage" }

Both directions matter: one row must be blocked and one near-miss must pass.

Key points

  • Write the policy as plain sentences before choosing any tool.
  • Provider moderation endpoints are fast and simple but cover only the provider's fixed categories.
  • Open-weight policy models like Llama Guard give control over data and taxonomy but cost hosting and generation time.
  • Frameworks and validator libraries cover flows and structure; cloud services trade portability for easy setup.
  • A tool is only shown to work when it is measured on a labelled set of your own traffic and attacks.

Common mistakes

  • Picking a tool by reputation instead of mapping it to the written policy.
  • Sending sensitive user text to a hosted checker without approval.
  • Testing only attacks and never the legitimate requests that should pass.
  • Measuring accuracy once and never again after the model or tool is updated.

Check yourself · 2 of 3

Which choice gives your team control over where the checked text is processed?

Choose one answer

Check yourself · 3 of 3

What is the best evidence that a guardrail tool will work for your product?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic