Writing custom actions for NeMo Guardrails

Custom actions let an organization put its own checks and system integrations inside NeMo Guardrails flows. This page explains how they are written, run and tested, and what drives the effort.

On this page

When custom actions for NeMo Guardrails are the right tool

An assistant needs an organization-specific check, such as validating a customer identifier against an internal system, looking up an account status, or applying a policy that no built-in rail covers. In NeMo Guardrails, that logic enters the configuration as a custom action: a Python function that a flow calls through the execution rail. Custom actions are the mechanism for bringing organization logic into a configuration, so the first decision is whether the check truly needs code or can be expressed with an existing rail, a prompt change or a Colang flow alone. NeMo Guardrails has five rail types: input rails, dialog rails, retrieval rails for RAG chunks, execution rails for custom actions and tools, and output rails. Execution rails are the only type that runs your code, which makes them the place where internal calls and their risks concentrate.

Before writing an action, confirm the Colang version your configuration uses. Colang 1.0 is the default, and Colang 2.0 is also supported, so the flows that call your action will look different depending on the version. Confirm this with the colang_version setting in your config.yml and check the NeMo Guardrails Colang 2 migration guide if you plan to move a configuration between versions. Also confirm that your team runs Python 3.11, 3.12 or 3.13, the versions the current 0.25.0 release requires, since action code runs inside that environment. Then decide whether the action reaches an internal API, a database or a secret, because those integrations need credential handling and network access reviewed before the action is written.

Which kind of action fits which organization check

Use this shape when the check depends on data held in a system you already run, such as a customer record, an entitlement store, a ticket queue or an account status. The action receives values extracted from the conversation, calls the internal API with credentials it reads from configuration, and returns a value the flow can branch on. The surrounding flow has to handle slow or unavailable systems, because a lookup that times out should fail in a defined way rather than silently allow the request.

  • Input: a small set of named parameters, such as a user identifier or a requested resource, passed from the flow rather than the raw conversation.
  • Output: a boolean or a simple status value, returned in a form the flow can match on.
  • Failure path: a timeout or error branch that the flow explicitly routes to a block or fallback message.
  • Credentials: service accounts scoped to read-only queries, loaded from your secrets store and not hard-coded in the action.
  • Data minimization: return only the fields the decision needs, so the result does not place extra personal data into prompts or logs.

Confirm the exact action signature and how parameters are injected in the 0.25.0 documentation before you write the lookup, and test the timeout path as carefully as the success path.

How config.py injects parameters into actions

A custom action in NeMo Guardrails is a Python file placed in the configuration folder next to config.yml and the Colang files, and the runtime discovers it from that folder when the configuration is loaded. The action itself is an ordinary Python function that the flows call by name. Parameters that the action needs, such as an endpoint, a threshold or a list of blocked terms, are supplied through a config.py module in the same folder. The practical point for the team is that config.py is the place where the configuration loader reads values and passes them into the action at runtime, so the action code can stay generic and the values can differ between environments. Confirm in the NeMo Guardrails documentation for your pinned version exactly how config.py is loaded, how it is named and which parameters the runtime injects into the action signature, because these details have changed across releases and the current NeMo Guardrails documentation should be checked against the version you deploy.

The main design decision is how much to hard-code. Values written directly into the action are simple to read and review, and they avoid a second file to keep in step with the code. The cost is that every change to a threshold, a service address or a feature switch becomes a code change that must be tested and released again. Reading values from configuration keeps the action reusable across development, test and production folders, and it lets a compliance reviewer see which settings differ by environment. The trade-off is that configuration can drift from the code it controls, so the team should keep the set of injected parameters short, document each one, and write a test that loads each environment's configuration to confirm the action starts with the values it expects.

Secrets need a separate rule. A config.py file is Python source that sits in the repository and is often copied into container images, so an API key or database password written into it can end up in version control, build logs and image layers. Keep credentials in environment variables or the secret store your platform already uses, and have the action read them at runtime rather than receiving them as literal values from config.py. Before go-live, confirm that no value in config.py or config.yml is a credential, that the configuration folder is excluded from any public artifact, and that the server image does not bake in secrets. These controls should be written into the deployment checklist so the same review applies to every new action.

Local execution or the actions server: which to choose

This table compares running custom actions inside the application's Python process with running them on a separate actions server that the guardrails server calls. Read each row against your own team's release process, dependency footprint and isolation requirements. The main takeaway is that local execution is simpler to start with, while a separate actions server pays off when action code must change or scale independently of the application.

ConsiderationLocal execution in the application processSeparate actions server
IsolationAction code runs with the same process privileges, memory and network access as the applicationAction code runs in its own process or container, so credentials and network reach can be scoped separately
Dependency managementAction imports must install into the application's Python environment, so a conflicting library can affect the appAction dependencies live in their own environment, which keeps the application's dependency set smaller
Deployment unitActions ship inside the application image or package, and every action change needs an application releaseActions ship as their own deployment, and the guardrails server only needs to know where to reach them
ScalingAction work scales with the application instances that host itAction work can be scaled separately, though the exact server configuration should be confirmed in the documentation
Who can change action codeDevelopers who change the application code must also change actionsA separate platform or security team can own action code, subject to its own review and access controls
Setup effortLowest, since no extra service, network path or authentication is needed for action callsHigher, since it adds a service, a network connection and a way to authenticate calls between the two
What to confirmConfirm how your version of NeMo Guardrails loads action files from the configuration folderConfirm the current actions server behavior and configuration keys in the official NeMo Guardrails documentation before design

Writing and testing a custom action step by step

This sequence takes a team from a clean Python environment to a custom action that runs inside a guardrail flow, with checks at each stage so failures surface before the action reaches production traffic.

  1. Confirm the Python version

    Check that the workstation or build image runs Python 3.11, 3.12 or 3.13, the versions NeMo Guardrails 0.25.0 requires. Run python --version in the environment that will host the action and confirm the output before installing anything. Your platform team owns this check when the runtime comes from a shared image, so confirm it with them rather than assuming the default interpreter is suitable.

  2. Install the library into an isolated environment

    Create a virtual environment and install the nemoguardrails package from PyPI, pinning the version your organization has approved (0.25.0 is the current release at the time of writing). Record the exact version in your dependency file so later upgrades are deliberate. Done when pip show nemoguardrails reports the expected version and python -c "import nemoguardrails" runs without error.

  3. Create the configuration folder

    Create a folder for the guardrail configuration containing a config.yml file, a Colang file for the flow that will call the action, and a actions.py file for the Python code. Keep this folder in version control next to the application code. Done when the folder loads through the Python API with an empty or minimal flow, which confirms the model settings in config.yml are readable.

  4. Write the Python action

    Write an async Python function decorated as an action in actions.py, performing the organization-specific check, such as a lookup against an approved list or a call to an internal service. Declare the parameters you need, and let the framework inject context values from config.py where your design requires them. Keep credentials in environment variables or your secrets store, not in code. Done when the function returns a predictable value for a known good input.

  5. Reference the action from a flow

    In the Colang file, define a flow that calls the action by name and branches on its result, then connect that flow to an input or output rail in config.yml so it runs on every message. Confirm the Colang version you have set, since Colang 1.0 is the default and 2.0 uses different syntax. Done when the flow appears in the rail list and the configuration validates when loaded.

  6. Wire the outcome into input or output rails

    Decide what the action's result does: block the message, return a fixed bot response, or pass the content through. Use the return contract your team has agreed, and where the decision needs to be explicit, follow the RailOutcome pattern described in the sibling topic. Test both branches with one input that should pass and one that should be stopped. Done when each branch produces the expected bot response in the Python API.

  7. Run unit tests on the action directly

    Write unit tests that call the action function without the full rail pipeline, using a deliberately bad input such as an empty string, an oversized payload or a value that should fail the check. Assert on the exact return value and on the exception behavior. Run the suite with your standard test runner in CI. Done when the bad-input test fails the check as designed and the test suite passes on every commit.

  8. Run an end-to-end call through the Python API or server

    Send representative requests through LLMRails or the newer Guardrails class (LLMRails is deprecated in 0.25.0), or through the guardrails server's HTTP API if the configuration is deployed as a service. Compare responses against the expected pass and block cases, and confirm that logs show the action executed. Done when the end-to-end results match the test matrix, and the configuration is ready for review by your security team.

Returning decisions and content from an action

The return value of a custom action is what flows act on, so how an action expresses its result decides whether a user message is allowed, blocked or rewritten. An action that returns a bare value leaves the flow to guess what that value means, and a guardrail that guesses is hard to test and harder to audit. Before writing any action, decide which decision states your checks need (for example, allow, block and transform), agree how each one is expressed, and document the mapping from each action to the flow branches that consume it. The detailed contract for expressing these decisions explicitly is covered in the sibling topic on RailOutcome, so this section focuses on the operational consequences of getting the return path wrong.

Three failure modes account for most surprises in production. The first is an unhandled exception: if an action raises an error, the flow may stop, fall back to a default response, or continue with no decision at all, depending on how the configuration and the runtime handle errors in your version. The second is a missing value: an action that returns nothing, or a key the flow does not expect, can leave a branch undefined. The third is a flow that ignores the result: a Colang flow that calls the action but never branches on its output will pass content through unchecked, even though the check ran and logged a finding. Confirm in your environment how errors from actions surface, and add tests that force each path, including the error path, before relying on the check.

Plan for these cases in the design rather than in incident response. Give every action a defined fallback decision for errors and missing results, and choose deliberately whether a failing check should block the message or let it pass with a logged warning. For a regulated assistant, the fail-closed choice is usually easier to defend to a reviewer, but it has a cost in false blocks that the team should measure. Review the return contract against the NeMo Guardrails release you pin, because the supported return types and their handling have changed across versions and should be confirmed in the NeMo Guardrails documentation before you treat any of them as settled.

How a user message reaches a custom action and returns

The path starts when a user message enters the guardrails runtime and passes the input rails. A Colang flow then calls the execution rail, which invokes the Python action either in the local runtime or on the actions server. If the action queries an internal system, that call crosses the trust boundary, so the reader should check what credentials and network paths the action uses. The action's result returns to the flow, and only then does the output rail decide what reaches the user.

Request path from user input through an execution rail action to the user response.

Security risks in custom actions to review before release

Custom actions run with the permissions of the process that hosts them, so a weak action can expose credentials, data and internal systems to the model and its users. The six risks below are the ones to review before any action file reaches a shared environment, and each names the control to apply.

Credentials in config.py or action code

API keys and service passwords written into config.py or action modules end up in source control, container images and log output. Anyone who can read the repository or the image can reuse them. Load secrets from environment variables or a secrets manager at runtime, scope each credential to one action, and confirm that secret values never appear in the configuration files committed to the repository.

Internal API permissions broader than the user

An action often calls an internal API with a service account that can do far more than the person chatting with the assistant. A user who cannot read a record can still ask the bot to retrieve it. Authorize each call against the end user's identity or a narrowly scoped service role, and test with a low-privilege user to confirm that denied requests stay denied.

Retrieved text reaching action arguments

When a retrieval rail passes document text into an action parameter, instructions hidden in that text can change what the action does, such as the target URL, the record ID or the amount. Treat retrieved content as untrusted input. Validate every argument against an expected type, range or allowlist inside the action, and never pass free text directly into a query or command.

Unbounded outbound calls

An action that calls external services without limits can be pushed into repeated or long-running requests by a crafted prompt, which raises cost and can exhaust connections or quotas. Set explicit timeouts, retry limits and a maximum payload size on every HTTP client, and restrict outbound destinations to the hosts the action needs. Confirm these limits with a load test before release.

Logging of sensitive payloads

Debug logging inside an action can write full prompts, retrieved records or API responses to log storage that has weaker access controls than the source system. Log action names, durations, status codes and decision outcomes, and redact personal or account data before anything is written. Check the log output of a test run against the data classes the action handles.

Access control over action files

Action files and config.py define what the assistant can do, so changing them is a security change. If developers can edit them without review, a single commit can add a new external call or widen a permission. Require code review and protected branches for these files, limit who can deploy them, and record who approved each release.

Questions teams ask before writing custom actions

How much effort does a typical custom action take?

Effort depends mostly on what the action must reach and how many decisions it encodes, not on the Python itself. A small action that calls one internal service with a fixed rule is a short piece of code, while an action that queries several systems, handles authentication, returns structured decisions and needs test coverage takes considerably longer. The main drivers are the number of external systems, the quality of the business rule the action enforces, error handling for timeouts and bad responses, and the test harness. Ask any provider to break the scope into those components, and confirm which parts are one-time build work and which recur as the internal system or policy changes.

Can an in-house team write custom actions without outside help?

Yes, if the team has Python developers who can work with the NeMo Guardrails configuration model and access to the internal systems the action must call. Many teams start in-house for a single well-defined check and bring in a partner when the action needs to be reviewed for security, wired into an existing actions server, or tested against a broader set of failure cases. Decide early who owns the action after launch, since a check that nobody maintains will drift away from the policy it was written to enforce.

What skills and access does a custom action project need?

Plan for three inputs: Python skills, access to the systems the action calls, and test data that reflects real requests. The developer should be comfortable with Python packages, HTTP clients, exception handling and unit testing. Access means service accounts or API credentials scoped to the minimum the check needs, plus a non-production environment to exercise them. Test data should include normal inputs, borderline inputs and adversarial inputs, and it must be cleared for use in your environment. Confirm with your security team how those credentials will be stored and rotated before development starts.

How long does a first custom action take to reach production?

No general duration can be stated with confidence, because the timeline depends on the approval path, the readiness of the internal APIs, and how much testing your change process requires. The development step is often the shortest part. Delays usually come from waiting for access to systems, agreeing on what the action should return when it cannot decide, getting a security review of new outbound calls, and running the change through your release and approval process. Ask for a written plan with milestones for access, build, testing and deployment, and confirm each dependency with the owners of the systems involved.

What would an outside partner scope for a custom action engagement?

A partner should scope the work in writing before starting. The usual items are the business decision the action enforces, the internal systems and data it touches, the inputs taken from configuration, the expected return values and how each outcome is handled, the test cases and the environment where they run, the deployment model (local execution or a shared actions server), and handover documentation. DeployOpen plans and delivers this kind of work as fixed-scope engagements, with scope, deliverables and timelines agreed in writing before work starts, and a quote follows from that written scope.

How does the Apache 2.0 license affect our own action code?

NeMo Guardrails is licensed under Apache 2.0, and that license governs the NeMo Guardrails code you use. Code you write for your own custom actions is your code, and whether and how you distribute it is your decision, but you should still have your legal or licensing team confirm the terms that apply to any dependencies your action pulls in. Keep track of third-party libraries your action imports, because their licenses apply to them separately. Confirm the license terms against the repository's LICENSE file rather than relying on this summary.

What should we check in an action before it goes into production?

Check that the action fails safely, that it logs enough to investigate a blocked request without storing sensitive content, that its credentials are scoped and not hard-coded, and that its tests run in your continuous integration pipeline. Also confirm the action's return behavior matches the rail design, so that a timeout or unexpected response produces a deliberate outcome rather than an accidental allow. Review any outbound network calls with your security team, since an action that reaches internal systems extends the attack surface of the application.

Limits to confirm in your environment before you build

Custom actions depend on the NeMo Guardrails version, Python runtime, configuration style and the product path NVIDIA has set for the microservice. Confirm each limit below against your own environment and your vendor's release notes before you write or deploy any action.

Python version and dependency pins

NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13, so an action written for an older interpreter may fail at import time. Pin the exact library version in your lock file and build the actions server image from the same pin. Ask your platform team which Python build your container base image provides, and rerun the action tests after any change to the interpreter or to transitive dependencies.

Supported Python versions
3.11 to 3.13
PyPI package page

Action signatures in your deployed version

Action signatures, how parameters are injected from config.py, and how the actions server loads and reports errors can change between releases. Read the release notes for every version between your current pin and the target, and confirm the signature your actions use against the documentation for that exact version. Treat any mismatch as a blocking test failure rather than a warning.

Current release
0.25.0
Release notes

Microservice sunset and the NeMo Platform path

NVIDIA has retired the NeMo Guardrails microservice, with NGC listing it as sunset as of October 1, 2026 and no further releases. If your actions were designed to run on that container, ask your NVIDIA account team how the workload moves to NeMo Platform, and confirm where NeMo Helix fits as an inference gateway that applies guardrail configurations to model endpoints. Do not assume an actions server built for the microservice carries over unchanged.

NGC catalog entry

Colang 1.0 or 2.0 for flows

Colang 1.0 is the default, and Colang 2.0 is also supported, so your action calls from flows must match the dialect your configuration uses. Decide the dialect before you write actions, because flow syntax that invokes an action differs between the two. Confirm with your team which dialect your existing configurations use, and test each action from a flow in that dialect.

NeMo Guardrails docs

Manual review after migration

NVIDIA's convert tool can move Colang 1.0 configurations to 2.x, but NVIDIA states that converted configurations still need manual review. Any action invoked from a converted flow should be re-read against its new call pattern, including its return values and how it handles errors. Plan a review step in your migration and cover each converted action with a test that runs the flow end to end.

Colang 2 migration guide

Vendor questions before committing

Ask your vendor or NVIDIA account team which NeMo Guardrails version they support for your deployment, whether custom actions are covered by any support commitment, and what changes they expect in the next minor release. Ask for the upgrade path in writing and for the named owner of the actions server. Record the answers in the design document so the build plan reflects them.

Earliest LLMRails removal
0.27.0

How DeployOpen scopes and delivers custom actions

DeployOpen approaches custom actions for NeMo Guardrails as a scoped engagement inside your own infrastructure. We agree the checks, integrations and test evidence in writing first, then build, verify and hand the actions over with documentation your team can run and extend.

How we scope

  • Inventory the organization-specific checks and external systems each custom action must call before any code is written
  • Agree in writing which actions run locally and which run on the actions server, and where secrets and parameters come from
  • Define the fixed scope, deliverables and timeline for the actions, with retainer support offered separately if you want it

How we build

  • Implement Python actions with the input and output contract your Colang flows and rail outcomes expect
  • Wire configuration parameters from config.py and your secrets store so no credentials sit in source files
  • Write unit tests for each action and integration tests against a staging copy of the systems it calls

How we hand over

  • Deliver the action code, test suite and deployment steps for both local execution and the actions server
  • Document each action's inputs, failure behavior and logging so your engineers can change it safely later
  • Walk your platform and security teams through the handover and confirm they can run the tests themselves

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer when your NeMo Guardrails version changes
  • Retest custom actions after NeMo Guardrails upgrades, including changes to action interfaces and the actions server
  • Review new actions for injection exposure and permission scope before they are added to production configurations

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.