Guardrails (content rules)
This guide describes the Guardrails tab of a RAG Topic and of a GraphRAG Topic. You find it on the topic detail page, between Prompts and Data Upload. The tab is the same for both kinds of topic.
Guardrails check what users ask and what the topic answers. They can also black out single passages of an answer, for example names or phone numbers. Each topic has its own rules. Everything is off until you turn it on.
| Do not mix this up with the Guardrails module of the pipeline editor. That module checks text inside an agent pipeline. The guardrails on this page belong to a topic and work in every chat with it, also when another topic or an agent calls it. |
1. What a topic can check
| Check | What it does |
|---|---|
Word and pattern lists |
A question that contains one of your words, or matches one of your patterns, is blocked at once. No model is asked, so this is fast and free. |
Safety model |
A small model made only for safety checks, for example Llama Guard, Qwen3Guard or Granite Guardian. It is fast and cheap. It uses its own built-in list of unsafe topics. |
Checking AI model |
A general AI model that reads the question or answer and decides if it breaks one of the rules. It understands context and your own rules better than the safety model, but it is slower and costs more. |
Blacking out |
Instead of withholding a whole answer, single passages are covered by black bars. The rest of the answer stays useful, and the sources stay. |
In which order
A question is checked first. The cheapest check runs first: your lists, then the safety model, then the checking AI model. The first check that blocks ends the chain, and nothing else runs. There is no search, no tool call and no answer.
When the question passes, the topic writes its answer. Then the answer is checked the same way, and passages are blacked out.
What the user sees
-
A blocked question gets your message (or "I can’t help with that request."). No sources are shown, and a note under the answer names the rule that blocked it.
-
A withheld answer is replaced by your message (or "The answer was withheld because it violates this topic’s content rules."). No sources are shown, and a note names the rule.
-
Blacked-out passages are black bars as wide as the hidden text. The answer keeps its sources. A note says how many passages were hidden. The hidden text itself never reaches the browser.
|
The answer arrives all at once. To check an answer or black out parts of it, the topic has to hold it back until it is complete. With an answer check or blacking out on, users do not see the answer appear word by word, and answers take longer. |
|
A checking model that cannot be reached never lets text through. The user then sees an error and can try again. The checks do not fail silently, but a model that is down also stops the chat. For this reason, use models that run reliably. |
2. The tab, section by section
Turn on content rules is the master switch. While it is off, nothing on the page is used, and the chat works as before. A box under the switch warns you when the rules are on but nothing would check or black out anything.
Safety model (fast check)
Choose the AI server and the model. The server has to be registered under Admin → AI Servers. You can pick the model from the list or type its name. Also block "controversial" content only matters for Qwen3Guard, which can answer "controversial" for borderline content. On: such content is blocked too. Off: only clearly unsafe content is blocked.
The safety model uses its own built-in topics. The topic lists further down do not apply to it.
Checking AI model
By default the checking AI model is the topic’s own Language Model. You can choose another server and model instead, for example a stronger one. Your own rules go in the Your own rules field, one rule per line, in your own words:
Only answer questions about our products.
Never name a competitor.
The rules apply to questions and answers. A text that is outside what a rule allows breaks that rule. More rules make the check slower.
Questions
-
Check questions turns the whole direction on or off. The two ticks with the safety model and with the checking AI model choose which models look at questions.
-
Blocked words: one word or phrase per line. Whole words only, upper or lower case.
-
Blocked patterns: one pattern (regular expression) per line, for example
\d{16}for a 16-digit number. A pattern is case-sensitive unless it starts with(?i). The page checks that every pattern is valid, because an invalid pattern would stop the topic from starting. -
Topics not allowed in questions: the checking AI model blocks a question about one of the ticked topics. Fewer topics mean fewer blocked questions, but more that should have been blocked get through.
-
Message when a question is blocked: what the user sees. Leave it empty for the default.
Answers
The same, without lists. Topics not allowed in answers includes System prompt leak, which catches answers that reveal the assistant’s own instructions.
Blacking out
Words and patterns are blacked out every time they appear in an answer. Kinds of text to black out lets the checking AI model find text by kind, for example Personal data. This needs the checking AI model, and it costs one more model call per answer. A model can miss something or black out too much. For texts that must never appear, use words and patterns as well.
Blacking out works also when Check answers is off.
Rule texts
For each topic, the checking AI model gets a short rule text that says what the topic means. Open one to read it. You can change it, for example to make Personal data mean exactly what your company counts as personal data. Saving the built-in text back removes your change, so the topic keeps following the built-in one.
Checking model prompts
The two instruction texts the checking AI model is sent: one for questions, one for answers. Change them only
when the built-in ones do not fit. Your text replaces the built-in one completely. Keep the answer format, and
keep the number of %s placeholders: the page refuses a text with the wrong number.
3. Saving and restarting
Save content rules checks the settings and saves them. The button stays at the bottom edge of the page while you scroll, so it is always in view, wherever you changed something. It saves every setting from the switch down to Blacking out. The rule texts and the two prompts save one by one, when you press Save in their own window.
A change reaches a running topic only after a restart. Until then the topic keeps working with the old rules. So when the topic runs, Save content rules opens the window Restart Required:
-
Save & Restart saves and restarts the topic at once. On Docker the chat is unavailable for a moment. On Kubernetes the topic’s servers are replaced one by one, so the chat keeps working.
-
Save Only saves. The rules apply at the next restart.
-
Cancel saves nothing. Your entries stay in the form.
A stopped topic is only saved; it uses the rules at its next start. This works the same on the Guardrails tab of a GraphRAG Topic.
| A topic that was started with an older version of the topic image does not know the rules at all. Update the image first, by stopping and starting the topic. |
The topic does not start when a setting is invalid, for example a safety model without a server, an invalid pattern, or blacking out by kind without the checking AI model. The tab refuses to save such a setting.
4. Good practice
-
Start with the word list and one model. Test with questions you know should be blocked, and with harmless questions that must not be.
-
Use the safety model as the first check and the checking AI model for your own rules. The safety model is quick, so most questions never reach the slower model.
-
Keep your own rules short and clear. One rule per line is easier for the model than a paragraph.
-
A stronger checking model finds more but makes every answer wait longer. Test the speed with your real questions.
-
Guardrails reduce risk, they do not remove it. A model can miss a violation and block a harmless text.
-
Test your rules with the Evaluation area. See Testing your rules.
5. Testing your rules
Test runs of the Evaluation area ask the Topic with its content rules on, like a real user. You can use this in two ways.
Check that the rules act. In a test set, give a question the setting Content rules (guardrails):
-
Must be blocked for a question that the rules have to stop, for example one with a blocked word or a forbidden topic.
-
Must contain blacked-out text for a question that makes the Topic write something that you black out, for example a phone number.
Optionally name the kind of rule (the category) that has to act. The run then rates the question with the measure Content rules: 1 when the rules did what you expect, 0 when not. No rating model is needed for this measure. A question that must be blocked is rated by no other measure, because there is no answer to rate. Questions that make the Topic write sensitive text can fail now and then with Must contain blacked-out text, because the model may not write that text this time. For questions, Must be blocked is more reliable.
Keep the rules from spoiling other tests. A question that is blocked without being meant to is marked in the results with a yellow "no entry" sign, and the run lists it in its own finding. It does not count as a weak answer, and the other findings leave it out. Its ratings still count in the averages. To measure only the search, switch the rules off for the run. The start dialog reminds you when the Topic has content rules on.
See Test sets and The measures.
6. Management REST API
The same settings are the guardrails group of POST /api/v1/topics, POST /api/v1/graphrag-topics, and their
PATCH and GET calls. See the Management
REST API page.