Why guard SQL and shell tools in AI agents with NeMo Guardrails
NeMo Guardrails can validate the tool calls an agent proposes to run SQL or shell commands and scan the results sent back to the model, but database and operating system permissions must still enforce the limits. A guardrail is one check in the application's path. If it fails open, misparses a statement, or is skipped by a new code path, the database or host is exposed. Before building anything, list every tool the agent can reach, the account each tool runs under, and the data and commands that account can read or change. The rails stop obviously unsafe requests early, while the database role, the OS account and the network path are the controls that hold when the rails do not.
NeMo Guardrails is an open-source library licensed under Apache 2.0 that wraps an LLM application with configurable rails. Its documentation describes five rail types: input rails check user messages before the model sees them, dialog rails steer multi-turn conversations, retrieval rails check RAG chunks, execution rails check the inputs and outputs of custom actions and tools, and output rails check what the model returns. For SQL and shell agents, execution rails are where a proposed query or command can be inspected before it runs, and output rails are where query results can be scanned before they reach the user or the model again. The library can be called from Python or run as a guardrails server with an HTTP API, so the checks can sit between the agent and the tool.
Teams need this layer when an agent can change business data, run commands on hosts, or take instructions from content that users or documents can influence. A read-only agent over one reporting schema carries less risk than an agent with write access to a production database, so the depth of checks should follow the privileges granted. Two facts shape the current path. LLM Guard, an input and output scanner project, was archived in July 2026 and is no longer maintained. NVIDIA's NeMo microservices were sunset as of October 1, 2026, so the open-source library is the current path. Confirm the release you intend to pin, which the PyPI listing shows as 0.25.0 at the time of writing, and check its Python version requirement before planning the build.
Which guard layer fits each SQL and shell risk
Schema validation checks that a tool call has the expected shape before anything runs: required fields, types, enumerated values and length limits. For SQL, it can confirm that the tool receives a named query template with typed parameters instead of a free text statement. For shell, it can confirm that the command name comes from a fixed list and that arguments match declared types. It is the cheapest layer and it fails closed when the shape is wrong, but it checks structure, not intent.
- Catches: malformed arguments, missing fields, wrong types and tool names outside the declared set.
- Misses: a syntactically valid SQL string that selects every customer row, or an allowed command pointed at a hostile path.
- Depends on: the tool definitions in your configuration and the tool-call rails in the IORails engine, which the sibling tool-rails topic covers. Confirm that your version enforces them on the path you use.
- Weak spot: a free text
queryfield gives this layer almost nothing to check.
Check that every tool the model can call has a schema tight enough to reject anything your team would not run by hand.
CEL (Common Expression Language) rules express conditions over parameter values, such as allowed tables, row limits or path prefixes. This is where policy such as reads only from the reporting schema or no paths outside the working directory is written down as testable logic. Confirm in the documentation for your NeMo Guardrails version whether CEL expressions are evaluated natively or must be implemented in your own code, and in which engine they run, before you design around them.
- Catches: table names outside an allow-list, missing or oversized LIMIT clauses, paths outside an approved prefix and flags such as recursive delete.
- Misses: risks the parameters do not expose, such as a join that reads sensitive columns through an otherwise allowed table.
- Depends on: the rule evaluation path in your version. If the checks run inside an execution rail for a custom action, the sibling execution-rails topic explains the inputs and outputs it sees.
- Keep rules narrow: an overbroad rule blocks legitimate work and pushes users toward workarounds that bypass the agent.
Ask for a blocked and an allowed test case for each rule, and confirm where the rule is evaluated.
A judge check sends the proposed SQL or command, the user request and the written policy to a second model, which returns allow or block. It can assess intent that schemas and expressions cannot, such as whether a DELETE matches what the user actually asked for. The judge is probabilistic, adds a model call to every guarded invocation and can itself be influenced by the same injected text it is meant to catch, so it should never be the only layer.
- Catches: mismatches between the user's request and the generated statement, and destructive actions that the policy describes in plain language.
- Misses: anything the judge model does not recognize, and it offers no guarantee of a correct decision on each call.
- Depends on: self-check style prompts or custom actions in your configuration. Judge model selection and where it is hosted are decisions for your team.
- Cost driver: the extra model calls recur on every guarded request, so latency and inference spend grow with traffic.
Ask how the judge is tested against labeled examples, and what the agent does when the judge call fails or times out.
Output scanning inspects what a query or command returns before the result reaches the model or the user. Results can carry personal data, credentials found in logs or configuration files, or instruction-like text inside data fields that tries to steer the agent. This layer addresses leakage and indirect injection from data, while the earlier layers decide whether the call should run at all.
- Catches: personal data and credentials in returned rows or standard output, and instruction-like text inside retrieved content.
- Misses: sensitive values without a recognizable pattern, and content hidden in results that are too large to scan in full.
- Depends on: output rails and tool-result checks. Confirm which of these applies to tool results in your version.
- Limit results at the source: row caps, column selection and output size limits reduce what must be scanned and what can leak.
Confirm how truncated results are scanned, and whether blocked results are logged in a form your incident response team can review.
Choosing schema, CEL, judge and output checks
This table compares five guard options for SQL and shell tools: schema validation, CEL rules, judge checks, output scanning, and allow-lists of statements or commands. Read each row for the workload where it fits, its main latency or false-positive cost, and what your team must keep current. In most deployments the allow-list and CEL rules carry the hard limits, while judge checks and output scanning catch what those rules cannot express.
| Guard option | When it fits | Main trade-off | What the team must maintain |
|---|---|---|---|
| Schema validation | Tool calls that pass structured arguments, such as a table name, a column list or a bounded row limit, for read-only analytics agents | Checks shape and types only, so a well-formed query can still read sensitive data | Tool schemas that match the real database objects and are updated when tables or columns change |
| CEL rules | Declarative conditions on tool arguments, such as blocking write keywords, requiring a tenant filter or capping result size | Fast to evaluate, but string-based conditions can miss obfuscated or nested SQL and produce false positives on legitimate queries | Rule set reviewed against new query patterns, with test cases for each rule and each blocked pattern |
| Judge checks | Write-capable operations agents where intent matters, such as deciding whether a shell command is a safe diagnostic or a destructive change | Adds a model call to each checked action, which adds latency and cost, and the judge can itself be wrong or manipulated | Judge prompt and model versions, a labeled test set of allowed and blocked actions, and a fallback when the judge is unavailable |
| Output scanning | Results returned from SQL queries or command output that may contain credentials, personal data or internal hostnames | Runs after execution, so it limits exposure but does not prevent the query or command from running | Pattern lists or classifiers for your data types, and a decision on whether to mask, truncate or block output |
| Allow-list of statements or commands | Narrow agents with a known set of tasks, such as fixed report queries or a short list of diagnostic commands | Strongest control for what it covers, but blocks legitimate requests that were not anticipated, which drives user friction | The approved list, a review process for additions, and removal of entries when tasks or systems change |
How a proposed SQL or shell call passes through the guardrails
The flow starts with a user request that the agent turns into a proposed SQL or shell call. NeMo Guardrails input and execution rails check the arguments against schema, allow-list and CEL rules before anything runs. Only approved calls cross the trust boundary, where the database or operating system executes them under its own account. A rejected call stops at the guardrails layer and never reaches the database or shell, and the output rails scan results before the response returns to the user.
Approved SQL or shell calls cross into database and OS permissions, while rejected calls stop at the guardrails layer.
Setting up guarded SQL and shell tools step by step
This sequence takes an agent that can run SQL or shell commands and puts the database and operating system permissions in place first, then layers NeMo Guardrails checks on top, so each control is verified before the next one is added. The result is a tested configuration where blocked and allowed tool calls behave as designed.
Confirm the Python runtime and install the library
The platform engineer confirms the host runs Python 3.11, 3.12 or 3.13, which are the versions NeMo Guardrails 0.25.0 requires, then installs the nemoguardrails package from PyPI into an isolated virtual environment pinned to that release. Pinning matters because the 0.25 release deprecates the LLMRails class in favor of Guardrails, so code written against older examples may need changes. The step is done when the package imports cleanly and the installed version reports 0.25.0.
Define tool schemas and allow-lists
The team writes down every SQL statement type and shell command the agent may request, along with the argument schema for each one. For SQL, this means named query templates, permitted tables and columns, and row limits. For shell, it means a fixed set of executables and argument patterns, with no free-form command strings. Security and data owners review the list before any rail is written. The step closes when the schema files are committed to version control and a reviewer has signed off on each permitted operation.
Restrict the database role and OS account
The database administrator creates a dedicated role with read-only grants on the specific tables and views in the allow-list, and no DDL, no superuser rights and no access to credential tables. The operations team creates a separate OS account for the agent process with no sudo rights, a restricted working directory and no network access beyond what the tools need. Guardrails are not a substitute for these controls, so they go first. The step is done when a test connection with the agent role can read permitted tables and is refused on a forbidden table, and the OS account is refused on a forbidden command.
Write config.yml and Colang flows
The developer creates a configuration folder with a config.yml file that names the model, the rails to enable and the paths to any Colang files. Colang 1.0 is the default, so teams starting fresh can use it unless they need 2.x features. If Colang 2.0 is chosen, the team uses the 2.x syntax from the start rather than converting later. Flows route tool calls through the checks defined in the schema step. The step is done when the server or Python API loads the configuration without errors and logs the active rails at startup.
Add custom actions that run the checks
The developer implements Python actions that validate each proposed SQL statement against the allow-list, reject multi-statement input and enforce row limits, and validate shell arguments against the fixed patterns. Each action returns a clear pass or fail value that a Colang flow can branch on. Actions should fail closed, meaning any parse error or unknown tool blocks the call. The step is done when unit tests show that a semicolon-chained statement, a DROP statement and an unlisted executable are all rejected by the action itself.
Enable the IORails engine for tool rails
If the design needs tool call validation on the model's structured output, the developer enables the experimental IORails engine in configuration and confirms which rail types apply to tool calls and tool results. Teams should confirm current engine requirements in the NeMo Guardrails documentation, because the choice between IORails and execution rails affects where checks run. Judge checks and output scanning are added only after the schema checks pass. The step is done when a deliberately malformed tool call is stopped by the rail and the event appears in the logs.
Test blocked and allowed cases
The QA team builds a fixed test set with allowed queries, forbidden statements, injection attempts that wrap a DROP inside a legitimate-looking SELECT, shell commands with chained operators and oversized result requests. Each case has an expected outcome, and the run is repeated after every configuration change. The team also confirms that the database and OS denials still hold if the guardrail layer is bypassed in a test environment. The step closes when every case matches its expected result and the test report is archived with the configuration version.
Why database and OS permissions must back every guardrail
Guardrails are a filter, not a sandbox. A NeMo Guardrails configuration can check a SQL statement against a schema, a CEL rule or a judge model and block it before the tool runs, but none of those checks limits what the database or operating system will do if a check is wrong, bypassed or never reached. The database role and the OS user the agent runs under decide the real blast radius, so the team should design those controls first and treat the rails as one layer above them. Confirm each of the following in your own environment rather than assuming it: the agent connects with a read-only database role unless a write is explicitly required; that role is scoped to specific schemas, tables and, where the database supports it, rows; and the agent's service account is separate from application accounts and from any administrator account.
Shared credentials are the failure most often missed. Check that no admin password, superuser connection string or cloud key is placed in the config folder, a Colang file, an action's environment or the prompt, because anything the runtime can read is one prompt injection away from exposure. Shell tools need the same discipline: run the agent as a restricted OS user with no sudo rights, a locked-down home directory and an allow-list of binaries, and consider a container, chroot or similar isolation so a permitted command cannot reach host files or network segments it should not. Ask who owns each role, how credentials rotate and whether the database audit log records the agent's account separately, because the audit logging topic depends on that separation.
Ask your platform or security team to write these controls down as a test plan before the guardrails are tuned. Each permission should have a negative test, such as an attempted DROP or write from the read-only role, a query against a table outside the granted schema, and a shell command outside the allow-list, and the expected result should be a database or OS denial that holds even when the NeMo Guardrails check is disabled. The NeMo Guardrails documentation at NeMo Guardrails documentation covers the rail configuration, but the permission model belongs to your database and operating system owners, and the team that runs the agent should sign off on it.
Security and operational risks to plan for
Agents that run SQL or shell commands fail in a few predictable ways, and most of them cross the boundary between the rail and the database or operating system. Each card names the control that addresses the risk and the team that should own it, so the rails are not the only line of defense.
Prompt injection rewriting a query
A user or a retrieved document can instruct the model to change a SELECT into a statement that writes, drops or widens the query's scope. Schema validation and CEL rules check the final statement, not the intent of the prompt, so they must allow only the statement shapes the tool needs. Owner: the application team, with the database team enforcing read-only roles. Check that a rewritten query fails validation in a test suite that includes injected payloads.
NeMo Guardrails docsCommand chaining through shell metacharacters
A model-proposed command such as a harmless listing followed by a semicolon, pipe, backtick or subshell can run a second command the rail never evaluated. Allow-lists should match the parsed executable and its arguments, and the shell should not be invoked through a string interpreter. Owner: the platform team running the runtime, since the process user and sandbox decide what a chained command can reach. Confirm the rail rejects metacharacters and that the process cannot write outside its working directory.
Judge model failure or bypass
When a judge check is used for ambiguous SQL or shell requests, the judge can be wrong, slow, or tricked by wording that looks benign. A judge is a probabilistic control, so it should only add restrictions on top of deterministic checks and never be the sole approval for a destructive action. Owner: the security engineering team, who should test the judge with adversarial examples and document its false negatives. Confirm which model serves the judge and where its prompts are stored.
Output leaking sensitive rows
A query can pass every input check and still return customer identifiers, credentials or personal records that the user should not see. Output scanning and result-shape limits should run on returned rows before they reach the model or the user, and the database role should hold only the columns the use case needs. Owner: the data governance owner, who decides which columns are sensitive. Verify with a test dataset that seeded sensitive values are masked or blocked in responses.
Logging of blocked and allowed calls
Incident responders need to see the text that triggered a call, the parsed statement or command, the parameters and the authorization used, for both blocked and allowed calls. Logs that record only the final output miss the attempts that were stopped, which are often the most useful signal. Owner: the security operations team, with retention set by policy. Ask the platform which fields are logged, where they are sent, and who can read them, and confirm that log content does not expose the credentials used by the tool.
Fail-closed behavior when a rail errors
If a rail times out, a judge endpoint is unreachable or a schema file fails to load, the tool call must be refused rather than passed through. A fail-open setting turns every outage in a checking service into an unchecked path to the database or host. Owner: the application team configuring the rails, with the operations team testing failure modes before go-live. Confirm the configuration returns a refusal on each simulated error, and that the database and OS permissions still limit damage if the rails are bypassed.
Questions teams ask before guarding SQL and shell agents
What drives the effort and cost of guarding SQL and shell tools?
The main driver is how many tools the agent can call and how risky each one is. Every tool needs its own input schema, allow-list, judge criteria and output scanning, and a SQL tool touching production data needs far more review than a read-only query on a reporting replica. Other cost drivers are the number of database schemas and OS hosts involved, how many roles must be modeled, whether the team must build the permission layer in the database and operating system, and how much test coverage the security review expects. Ask any provider for a quote that lists each tool, the rail types applied to it, the permission changes on each database and host, and the testing and retest steps. Those line items are what you compare, not a headline number.
How long does a first build take for a few tools versus many?
Duration grows with the number of tools and with how much of the permission model is new. A first build usually covers one agent, a small set of read-only queries and one or two constrained shell commands, and the work is mostly schema definition, rail configuration and testing. Adding more tools repeats the same steps for each one, and write operations, multi-schema access or shell commands with arguments add review and test time. No timeline is fixed in advance. Ask for a schedule tied to a written tool inventory, and make sure it includes a verification phase where adversarial inputs are tried against each rail before the agent reaches users.
What must our internal team provide before the build starts?
The build depends on material only your organization holds. Expect to provide:
- The database schemas, table definitions and the columns that contain sensitive data
- The roles and entitlements each user group should have, and the accounts the agent will run under
- The shell commands, flags and paths the agent actually needs, and those it must never run
- Representative test cases, including expected allowed and blocked requests
- Logging, ticketing and change control rules that the guards must fit into
Without these, rules are written from assumptions, and test results will not show whether the controls match your policy.
Can one engineering team build and run these guards alone?
A single team with Python, database administration and Linux skills can build a limited version, but the work spans three areas: the agent and NeMo Guardrails configuration, database roles and grants, and host-level permissions for the OS account. Security review and compliance input are also usually needed for the allow-lists and the evidence. Teams that already own the database and operating system administration often keep the database and host work in-house and bring in outside help for rail design, judge prompts and adversarial testing. Confirm internally who approves changes to permissions and who will be paged when a guard blocks a legitimate request.
Do we need a consultant, and what would they cover?
A consultant is useful when the team lacks experience with rail configuration, adversarial testing or database and OS permission design, or when the deadline is tight relative to staff time. DeployOpen implements, hardens and tests open-source platforms inside your own infrastructure and runs security testing of AI agents, including tool permissions, data exposure and credential handling. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts. DeployOpen does not issue audit reports or certifications, so independent auditors still assess the controls. Ask for a written scope that names each tool, each permission change and each test.
How does the Apache 2.0 license affect what we pay?
NeMo Guardrails is licensed under Apache 2.0, so you can use, modify and deploy the library in your own infrastructure without a license fee for the software itself. Costs that remain are your compute, your staff time, any model or API usage for judge checks, and any external services you choose to integrate. The Apache 2.0 license governs the library, not the database or operating system you connect it to, and those products have their own terms. Confirm the terms of every component in your stack, and have your legal team review the license text before deployment. Note that NVIDIA has retired the NeMo Guardrails microservice, so check which packaging you intend to run.
How to prove the guards work before production
Before any SQL or shell tool goes to production, build a fixed test set of malicious and benign requests and run it through the full agent path, not just the rail configuration in isolation. The malicious set should cover the cases that matter for this topic: destructive SQL such as DROP, DELETE or UPDATE without a predicate, queries that reach tables outside the agent's allow-list, UNION-based and stacked statements, shell commands that chain with semicolons, pipes or subshells, attempts to read credential files, and tool results that carry injected instructions back to the model. The benign set matters just as much. Include routine reads, the parameter shapes your business users actually produce, and the commands your operators run daily, because a guard that blocks legitimate work will be disabled under pressure. Record for every case the expected outcome, the rail that should fire and the observed result, so a failure points to a specific control.
Treat every change to the configuration as a release that needs a full retest. That includes edits to schema validation files, CEL expressions, judge prompts, the output scanning patterns, the allow-lists and any change to the database role or the sandbox user behind the tool. Judge checks are probabilistic, so run the benign and malicious sets several times and record the spread of results instead of trusting a single pass. Confirm the fail-closed behavior by deliberately breaking the judge model endpoint and checking that the tool call is refused, not executed. Also test the database and OS layer directly: a request that slips past every rail should still fail because the read-only role lacks write privileges or the shell user cannot reach protected paths. Ask your team to document which layer stopped each malicious case, since a case caught only by a judge is weaker evidence than one blocked by a permission.
The test results are evidence only if you can show them later. Store the test set, the configuration version, the model versions and the run logs together, and link each run to the audit logging design described in the NeMo Guardrails documentation so you can show what text triggered a tool call and how it was authorized. For the broader testing approach, including per-rail benchmarks and vulnerability scans, see the NeMo Guardrails testing and evaluation topic. Confirm with your security and compliance leads which retention period and sign-off process they require before the first production run, and confirm the exact log and trace fields your installed release produces, since these vary by version.
How DeployOpen works on this
DeployOpen plans, implements, tests, documents and supports self-hosted open-source platforms inside your own infrastructure. For SQL and shell tools in AI agents, we start from the written scope, build the guardrail configuration and the database and operating system permissions behind it together, and hand over the evidence your security and platform teams need to review it.
How we scope
- Inventory every SQL and shell tool the agent can reach, with its database roles, host accounts and intended commands.
- Agree which schema checks, CEL rules, judge checks and output scans apply to each tool before build starts.
- Record scope, deliverables and timelines in writing, since most engagements are fixed-scope and quoted from that document.
How we build
- Implement the NeMo Guardrails configuration, Colang files and any custom actions in the environment you control, with versions pinned.
- Restrict database accounts and operating system permissions so the rails are backed by least-privilege access, not only prompt wording.
- Test blocked and allowed tool calls, including prompt injection attempts that try to widen SQL or shell access.
How we hand over
- Document each tool's rules, permissions, fail-closed behavior and the known limits of the rails for your reviewers.
- Deliver configuration in your version control with a runbook for changing allow-lists and rules safely.
- Provide the test results and a findings report with fixes and a retest, so your team can show how the controls work.
How we support
- Support upgrades to NeMo Guardrails releases, confirming the configuration still behaves as tested after each change.
- Offer ongoing support, upgrades and continuous testing as a retainer, scoped in writing.
- Ask your team to confirm during scoping which NeMo Guardrails deployment option and Python version your environment will run.

