Topical rails in Colang: keeping a NeMo Guardrails bot on topic

Learn how to write Colang intents and refusal flows that keep a NeMo Guardrails assistant on approved topics, how many example utterances to write, and when a classifier is the better choice.

On this page

Keeping a NeMo Guardrails assistant on topic in Colang

An assistant serving customers or citizens has to decline requests outside its remit, such as a banking bot asked for medical advice or a public service bot asked to write code. In NeMo Guardrails, topical rails handle this by defining user intents for off-topic subjects, pairing each intent with a fixed bot refusal, and writing a flow that connects the two. Topical rails are dialog rails in the five-rail model, so they sit alongside input rails, retrieval rails, execution rails and output rails rather than replacing them. Teams need them when the policy is about what the assistant talks about, not whether content is harmful. The library is licensed under Apache 2.0, the current release is 0.25.0, and Colang 1.0 is the default syntax while Colang 2.0 is also supported. Confirm which Colang version your project uses before writing flows, because the intent and flow syntax differs between them.

The work starts with a written list of allowed and disallowed topics, agreed by the business owner and the compliance team. Each disallowed topic becomes a define user block with example utterances, and each one needs a define bot refusal that gives no sensitive detail and points the user to a supported channel. Example counts matter: too few utterances leave paraphrases unmatched, while overlapping examples across topics cause misfires. Plan a review loop with real-looking test phrasings, including borderline requests that sit near approved topics. Illustrative example: a bank's assistant might define a refusal flow for investment tips while still answering questions about account fees. Confirm with your own test set how many examples each intent needs before you trust it.

A classifier is the better choice when the disallowed topics are broad, change often, or are too varied to enumerate in example phrases. Colang intent matching works on the phrasing you wrote, so open-ended topic boundaries can produce false refusals or gaps. NVIDIA's topic safety and NemoGuard TopicControl models, covered in the sibling topic on TopicControl, offer a model-based alternative that judges each message against a topic policy. The trade-off is an extra model call, its hosting and its own evaluation, so ask your platform team what latency and infrastructure the model adds in your environment. Keep a regression suite of approved and refused requests, run it on every change, and record the results as evidence for your governance review.

How Colang defines on-topic and off-topic requests

A topical rail in NeMo Guardrails is built from a few connected pieces: user intents, bot messages and a flow that links them. The configuration lives in a config.yml file, Colang files and optional Python actions, and each card below covers one part you will need to write and check.

User intents as example utterances

A Colang file defines a user intent with a name and a set of example utterances that show what users say when they ask about a topic. Each intent is a statement the bot should recognize, such as a request for investment advice or a question about a competitor's product. Write examples that cover the phrasing your users actually use, including short and misspelled forms. Review the list with support staff before launch, because the examples define what the bot treats as the topic.

NeMo Guardrails docs

Bot refusal messages

A bot message definition holds the text the assistant returns when a request falls outside the allowed scope. Keep refusals short, state what the assistant can help with, and avoid repeating the user's wording back to them. Write one refusal per off-topic category so the team can review each one separately. Confirm with legal or compliance owners which refusal wording they must approve, since the text is what users see.

A flow that connects intent and response

A Colang flow matches a user intent and then triggers a bot message in response. For a topical rail, the flow usually matches the off-topic intent and replies with the refusal, which stops the conversation from continuing on that subject. Keep flows for off-topic requests separate from flows for on-topic dialog so changes to one do not alter the other. Test each flow with a set of sample messages before enabling it in a shared environment.

The config.yml file

The config.yml file names the model that backs the guardrails configuration and lists the rails that are active. This is where you enable the rails that run on each turn and set the model parameters the engine uses. Record each change in version control, since a single key can switch a rail on or off for every conversation the server handles. Confirm the exact keys for your installed release in the documentation before you write them.

Optional Python actions

Python actions extend the configuration when a topical decision needs logic that Colang alone does not express, such as a lookup against an internal list of approved products. An action runs inside your deployment, so it can call internal systems, but it also becomes code your team must review, test and maintain. Limit actions to the cases that need them, and document which inputs each action reads and what it returns.

Verifying the rail before release

Before a topical rail goes live, run a set of on-topic and off-topic messages through it and record which ones the flow catches. Include borderline requests that sit close to the allowed scope, because these show where examples are missing or too broad. Keep the test set under version control so each configuration change is checked against the same cases. Ask the team who will maintain the rail to own this test set after handover.

How many example utterances a topical rail needs

No fixed number of example utterances is documented as correct for a Colang topical rail, so the honest answer is that the count depends on your traffic and your policy boundary. Three things drive it: how varied users' phrasing is, how close the off-topic and on-topic subjects sit to each other, and how carefully the team tests borderline requests before enforcement. A bot that handles a narrow product domain with clearly separate subjects may need far fewer examples than one that sits next to adjacent topics such as billing questions, account security or medical information. Before you write a single define user block, confirm the current guidance on example counts and matching in the NeMo Guardrails documentation, because matching behavior has changed across releases and your configuration should be checked against the version you run.

Start from real traffic rather than from invented phrasings. Pull a sample of user messages from your logs or pilot sessions, group them by what the user actually wants, and write the on-topic and off-topic intents from those groups. Then add near-miss examples on both sides: off-topic requests that share vocabulary with your product, and on-topic requests that use words an over-eager rail might treat as out of scope. These near misses are where false refusals come from, so they deserve more attention than the obvious cases. Keep the examples in the intent definitions and avoid duplicating the same phrasing with minor word changes, which adds volume without adding coverage.

Measure the result instead of judging the count by eye. Hold back a test set of labeled on-topic and off-topic messages that you never use while writing examples, run it against the configuration, and track two numbers: how often legitimate requests are refused (false refusals) and how often off-topic requests get through. Review every false refusal with the product owner and decide whether to add an example, reword an intent, or accept the trade-off in writing. Repeat the test after each change and after each NeMo Guardrails upgrade, since a larger example set does not guarantee better behavior. If false refusals stay high after several rounds, the team should weigh whether a classifier model fits the policy better, which the sibling topic on TopicControl covers.

Colang 1.0 or Colang 2.0 for a topical rail

Colang 1.0 is the default version in NeMo Guardrails, so a new topical rail project that does not need Colang 2.0 features starts here without extra configuration. Your topic rules live in .co files that define user intents with example utterances and bot responses that refuse out-of-scope requests, alongside a config.yml that names the model and rails. Because the default path is the one the documentation and the README describe first, it is the simplest place for a team to start and to hand the project to another engineer.

  • Default behavior: Colang 1.0 is used unless you select 2.0, so the configuration needs no version switch.
  • Intent definitions: Write define user ask off topic blocks with example phrasings and a define bot refuse off topic response.
  • Flow wiring: Connect the refusal to a define flow that runs on the matched intent.
  • Tooling fit: Confirm in the current documentation which features your topic design needs before committing to 1.0.
  • Future move: Plan a review of the version choice before adopting IORails, since it accepts only Colang 1.0 per the sibling topic on engine choices.

Before you build, confirm that your topic rules do not depend on a 2.0-only construct and record the version in your project notes so reviewers know which syntax to test against.

Topical rail options and when each fits

This table compares four ways to keep a NeMo Guardrails assistant on topic: Colang intent and refusal flows, the NemoGuard TopicControl model, a self-check prompt, and a classifier-based input rail. Read each row for the fit, the LLM calls or model dependency it adds, and the tests to run before enforcing it. The main takeaway is that the right option depends on how many LLM calls and extra models your team can operate, and on how precisely you can describe the allowed topics.

OptionBest fitLLM calls or model dependencyWhat to test before enforcing
Colang intent and refusal flowsSmall, well-defined topic lists where you can write example utterances for each intent and a fixed refusal messageDialog rails use LLM tasks to match user turns to intents, so each matched turn adds model calls; confirm the cost with your chosen model providerParaphrases of each intent, borderline requests near allowed topics, and whether refusals fire for legitimate questions
NemoGuard TopicControl modelAllowed and disallowed topics described in natural language, where example lists would be hard to maintainDepends on the TopicControl model being available through NVIDIA's hosted service or a self-hosted NIM; confirm deployment and access terms with NVIDIABorderline requests on both sides of each topic rule, plus the on-topic or off-topic result for multi-turn conversations
Self-check promptQuick coverage using an LLM you already run, when a separate model is not wantedAdds an LLM call per checked message using your configured model; the result is only as consistent as that model's answers to the promptConsistency across repeated runs, prompt wording changes, and false refusals on short or ambiguous messages
Classifier-based input railPolicies that must run on every input with a predictable, reusable check, including organizations that want to avoid extra dialog flow stepsDepends on a classifier model that you select and host; NeMo Guardrails supports input rails with several model types, so confirm the model and its hosting with your teamCoverage on your own sample of allowed and disallowed requests, threshold settings, and how refusals are logged for review
Dialog rails and conversation steeringMulti-turn flows where the bot must ask for values, confirm steps, or redirect a conversation back on topicMultiple LLM calls per turn for intent matching and flow decisions; plan capacity and cost with this in mindTurns that should continue a flow, turns that should leave it, and regression tests after every change to example utterances
Combined approachAssistants where a fixed refusal path is needed for clear off-topic requests and a model handles ambiguous onesCombines the dependencies of the chosen options; document which rail handles each caseOverlap between rails, conflicts in refusal wording, and which rail produced each decision in logs

Where the topical rail sits in a request

The request starts in the client application, which sends the user message to the NeMo Guardrails runtime, either through the Python API or the guardrails server. Inside the self-hosted trust boundary, the runtime matches the message against the user intent examples in the Colang files and decides between two paths. Off-topic input takes the refusal path and never reaches the main LLM. On-topic input continues to the main model, and the output rails check the response before it returns to the client. Check that the boundary sits where your data actually leaves your infrastructure.

Off-topic messages are refused inside the runtime before the main model is called.

Setting up a topical rail step by step

This sequence takes a NeMo Guardrails project from an empty folder to a topical rail that refuses off-topic requests and stays in place as the configuration changes. Each step ends with a check you can run before moving on.

  1. Confirm Python and install nemoguardrails

    Confirm the engineer's workstation or build host runs Python 3.11, 3.12 or 3.13, since NeMo Guardrails 0.25.0 requires one of these versions. Create a virtual environment and install the nemoguardrails package from PyPI, pinning the version your team has approved so that the rail behaves the same in every environment. Check the install by running the nemoguardrails command-line help and confirming it returns without errors.

  2. Create the config folder and base files

    Create a project folder with a config.yml file that names the model the assistant uses, plus one Colang file for topics and flows. Keep the configuration under version control from the first commit, because every later change to topics, examples and refusals needs to be reviewed and traced. Check the layout by loading the folder with the chat CLI and confirming the assistant starts and answers a simple in-scope question.

  3. Define allowed topics and intents with examples

    Write user intent definitions in Colang for each approved topic, such as billing questions or product setup, and add a set of example utterances per intent that reflects how real users phrase requests. Include a few near-miss examples for each topic so the matcher learns the boundary. Owners of the policy, typically a product or compliance lead working with an engineer, should sign off on the topic list before it goes live. The check is that every approved topic has its own intent with examples and no two intents share the same examples.

  4. Write refusal flows for off-topic requests

    Add a flow for each off-topic intent that sends a fixed refusal message and, where useful, points the user to an approved resource. Keep refusal wording short and consistent with the policy text the business has approved, so that auditors and users see the same language every time. Decide whether the flow should also end the conversation or return the user to an in-scope prompt. The check is that a clearly off-topic test message triggers the refusal flow and returns the approved wording.

  5. Test borderline requests in the chat CLI and Python API

    Run the configuration in the chat CLI for quick iteration, then call the same folder through the Python API from a small test script so the behavior matches what the application will use. Send in-scope questions, off-topic questions and borderline phrasings, and record which intent matched each one. Tune examples where legitimate questions are refused or off-topic ones pass, and confirm each change with another run. The check is a short log showing the expected intent or refusal for every test message.

  6. Build a regression test set for the topical rail

    Save the in-scope, off-topic and borderline messages with their expected outcomes in a test file kept in the same repository. Run the set automatically whenever the Colang files, examples or model settings change, and treat any unexpected result as a failed build. Include multi-turn cases where a user shifts topic halfway through a conversation. The check is a passing test run on the current configuration, with failures blocking promotion.

  7. Promote the configuration through environments

    Move the reviewed configuration folder through development, test and production using the same artifact in each stage, changing only environment settings such as model endpoints and credentials. Record the approved configuration version and the test results in the release record so the team can show what was deployed and when. Confirm in production with a small set of canary messages that the rail refuses off-topic requests and passes in-scope ones. The check is that production behavior matches the results from the regression set.

When a classifier model beats Colang intents

Colang intents are the right first tool for a small, stable set of topics, but the cost of Colang topical rails grows with every topic you add. Each allowed or disallowed subject needs its own user intent, a set of example utterances and a bot refusal, and those examples have to be kept distinct from neighboring topics or the embedding match will drift. Before you commit to this approach, list the topics you expect to govern in twelve months, not only the ones in the first release, and ask who will review and extend the example utterances when a product team adds a feature. If that list is long or changes often, a trained classifier is the better candidate to evaluate, because its contract is a single on-topic or off-topic decision rather than a growing library of phrasings.

Multilingual traffic is the second trigger to test. Colang example utterances are written by your team, so every language your users write in needs its own examples, reviewed by a fluent speaker, and each new language multiplies the upkeep. Ask whether your assistant will receive requests in languages your team cannot review, and whether the off-topic phrasings your users produce in those languages will match the examples you wrote. A classifier generalizes across phrasings more naturally than a fixed example set, but its behavior on your languages is an empirical question, so verify it with a test set in each language before relying on it. Confirm the supported languages and any limits with the model documentation rather than assuming coverage.

A classifier adds an operational cost that Colang does not. It needs its own model endpoint, which means a hosting decision, capacity planning, latency budgeting, and a second component in your monitoring and change management. Weigh that against the recurring effort of maintaining intents, and plan the classifier's contract and its test cases before enforcement. The sibling topic on restricting topics with NemoGuard TopicControl covers the on-topic or off-topic contract, the hosted versus self-hosted NIM choice, and how to test borderline requests, so use it as the next read before you decide.

Security and operational risks of topic refusals

A topic rail is a security control, so it can fail in ways that matter to your risk owners. The cards below pair each risk with the control that catches it: testing, logging policy, access control on the configuration repository and change review.

Prompt injection that moves the bot off topic

Users can write messages that try to override the topic rules, for example by asking the bot to ignore its instructions or to role-play a different assistant. A Colang refusal flow matches intents, so an injected request can land on a flow the designer never intended. Test a set of adversarial phrasings against the deployed configuration before each release, and keep those phrasings in a regression suite. Pair topic rails with a dedicated input check for injection, since topic matching alone does not stop it.

NeMo Guardrails docs

False refusals that block legitimate users

An over-broad example set can refuse questions that belong to the approved domain, which frustrates customers and staff and can push them toward unmonitored tools. Measure refusal rates on a labeled set of in-scope questions and on borderline requests, not only on off-topic examples. Ask the team who owns the assistant to sign off on which refusals are acceptable before enforcement starts.

Logs that capture personal data in refused content

A refused message is still a message. Logs of blocked requests can hold names, account numbers or health details that users typed into an off-topic question. Define a logging policy that states what is recorded for refusals, how long it is kept and who can read it, and mask personal data before it reaches the log sink. Confirm the retention period with your privacy office rather than relying on defaults.

Access to the configuration repository

Topic rules, example utterances and bot responses live in files such as config.yml and Colang files, so anyone who can edit them can change what the assistant will discuss. Restrict write access to the configuration repository, require authenticated commits, and keep the production configuration tied to a reviewed branch. Review who holds write access during each access review cycle.

Configuration changes that were not reviewed

A single added example utterance can silently widen or narrow what the bot accepts. Require a second reviewer for any change to flows, utterances or the topic definitions, and run the regression suite as a gate in the pipeline. Record which version of the configuration was live at each point in time so an incident can be traced to a specific change.

Refusals that leave no audit trail

When a regulator, auditor or internal risk team asks why the assistant refused a request, the team needs evidence that the rule existed, was tested and was live at that moment. Keep the test results, the approved configuration version and the change approval together so they can be produced on request. Ask your compliance lead which artifacts they expect before the first review.

Questions buyers ask before outside help on topical rails

How much does outside help with topical rails cost?

DeployOpen does not publish a price list, and a quote follows from a written scope. The cost depends on how many topics the assistant must stay on, how many languages users write in, how deep the testing goes, and where the classifier models run. Most engagements are fixed-scope, so ask for the scope, deliverables and timeline in writing before work starts, and check whether the quote covers design, testing, handover and any retainer for later changes. The open-source library itself is licensed under Apache 2.0, so the software license is not a cost line item.

How long does a topical rails project take?

No duration is fixed here because the timeline depends on the scope agreed in writing. The main drivers are the number of topics and example utterances, the number of languages, the number of borderline cases the testing must cover, and whether the model serving path is already in place. Ask a provider to split the timeline into design, build, testing and rollout, and to state which parts depend on your team's review cycles or on access to your infrastructure.

What does the client need to provide for this work?

The work needs access and decisions from your side more than it needs code. Expect to provide the list of approved and disallowed topics, sample real user requests (handled according to your data policies), the business owner who decides borderline cases, a non-production environment with the model endpoints the bot will call, and reviewers who can judge whether a refusal is correct. Without a named owner for borderline decisions, the rules tend to drift after launch.

Can our internal team build topical rails without a partner?

Yes, if your engineers can write Python, maintain a config.yml file and Colang files, and run a test suite against their own assistant. NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13, and the Apache 2.0 license allows internal use. Teams with no prior Colang experience usually need time to learn the flow model and the matching behavior. An outside partner is most useful when the topic list is large, when several languages must be covered, or when the team needs an evidence pack for a security review.

Does the cost of topical rails change with the number of topics?

Yes. Each topic adds intents, example utterances, refusal responses and test cases, and overlapping topics add review work because the matcher must separate them correctly. Ask for the count of topics and their boundaries in the quote, and whether the price covers adding topics later. Topics that sit close to each other, such as billing and account access, often cost more to tune than unrelated ones.

How much does model hosting affect the total cost?

Hosting is usually the largest recurring cost after staff time. Classifier models and the LLM calls that dialog rails make each turn need compute, which you pay for in your own cloud, data center or on a hosted endpoint. The cost depends on request volume, latency targets and whether models run in an air-gapped network. Ask the provider which models the design assumes, where they run, and how their size and count were chosen. NVIDIA's current guardrails microservice has been retired, so confirm the serving path before pricing it.

What testing depth should we expect for topical rails?

Expect testing that covers on-topic requests, clearly off-topic requests and borderline cases, both in the main language and in any other languages you support. A reasonable scope includes a fixed test set kept under version control, a rerun after each change to example utterances, and a review of refusals by your business owner. Ask whether the quote includes this regression suite and whether you receive the test set and results as deliverables, since that is what you will reuse after handover.

Will a provider guarantee that the bot never goes off topic?

No responsible provider can promise that, because language models and matchers make probabilistic decisions and users can phrase requests in unexpected ways. What you can ask for is a defined scope, a documented test set, measured results on that set, and a retest plan after changes. Ask how refusals are logged so your team can review misses and false refusals after launch.

How DeployOpen works on this

DeployOpen plans and builds the topical rails for your NeMo Guardrails bot as a fixed-scope engagement, starting from the topics you must keep the assistant on and the topics it must refuse. The work covers Colang flows, intent examples, the configuration files and the tests that show the bot behaves as agreed.

How we scope

  • Written scope lists the approved topics, the refused topics and the sample requests each one must handle.
  • We confirm which Colang version your project uses, since 1.0 is the default and 2.0 is also supported.
  • Scope states whether a classifier-based rail is in or out, with the reasons agreed in writing before work starts.

How we build

  • We write user intents, example utterances and bot refusal responses in the config and Colang files for your project.
  • We test borderline requests near each topic boundary and adjust example sets to reduce false refusals.
  • We set up the NeMo Guardrails Python API or server deployment so the rails run in infrastructure you control.

How we hand over

  • You receive the Colang and config files, the action code, and the test cases used to check each topic rule.
  • Documentation explains how to add a topic, how to review a blocked request, and how to run the regression tests again.
  • We walk your engineers through the Colang 1.0 to 2.x conversion notes if the project moves between versions.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Retainer work can cover NeMo Guardrails version upgrades, reviewed as release notes and breaking changes are published.
  • Ask any quote to name who maintains the example sets and who approves changes to topic boundaries.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.