Testing text-to-SQL and template rendering paths with garak

garak's exploitation probes check whether model output can carry SQL or Jinja template injection into the systems that run or render it. This page covers which application designs need that test and how to run it safely.

On this page

Why text-to-SQL and template rendering paths need their own garak test

If your application takes model output and passes it to a SQL engine, a template renderer or a code interpreter, this is the test that checks whether that output can inject into those systems. A general jailbreak or toxicity scan will not show it, because the risk sits in how your application handles the text, not in what the model says to a user. garak's exploitation module covers this class of weakness: according to the module source in probes/exploitation.py, it probes for template injection, code injection and SQL injection, using the probes JinjaTemplatePythonInjection, SQLInjectionSystem and SQLInjectionEcho.

These probes test the model and the endpoint behavior you expose, not the database or the template engine. garak sends prompts through a generator, such as a REST endpoint configured in a YAML file, and evaluates the returned text. It can show that the model produced a payload that reached your application's response, which is the input your own code then executes or renders. Whether that payload actually changes a query result or runs on the server depends on your code, your query construction and your engine configuration, so a clean garak run does not prove those paths are safe. Confirm with your engineers which component receives the model output and whether that component applies parameterized queries, sandboxed rendering or allowlists.

Application designs that need this test are those where model output reaches an interpreter: natural-language-to-SQL reporting tools, assistants that build report templates from user text, email or document generators that render Jinja or similar templates, and agents that run generated code. Plan the test against the full path, including the endpoint your users call, so the scan sees the same system prompt, filters and parsing that production uses. Record which probe failed, the payload that succeeded and the downstream component that would have acted on it, because that record is what your remediation ticket and any later rescan need.

Which application designs need this test

Model output becomes dangerous when a downstream component treats it as code: a SQL engine, a template renderer or a workflow expression evaluator. The cards below are illustrative application shapes, and each one shows the path the output takes before it reaches an interpreter.

Natural-language reporting over a database

Illustrative example: a sales assistant turns a question such as "top accounts this quarter" into a SQL statement that the service runs against a reporting replica. The model output is concatenated into the query text, so a crafted answer can add clauses, read other tables or alter results. Check whether the service runs generated SQL under a read-only role, whether it restricts statement types and whether it parses the query before execution. Garak's SQL injection probes exercise this exact path.

garak exploitation probes

Agents that build SQL through tools

Illustrative example: an agent exposes a tool that accepts a SQL string, and the model decides which query to send. The tool wrapper often trusts the agent's arguments because the call looks internal. Injected text in a retrieved document can steer the model into writing a query the user never asked for. Check the tool schema, the database role behind it and whether the wrapper validates the statement independently of the model's intent.

Email and document templating with generated fields

Illustrative example: a support tool drafts a customer letter, and the model fills named fields that a template engine renders into a PDF or email body. If the generated field contains template syntax, the renderer may evaluate it, which can expose object attributes or server-side values. Check whether generated text is inserted as data or compiled as template source, and whether the sandbox limits attribute access and filesystem calls.

Low-code workflow builders

Illustrative example: a no-code automation product lets a model produce values that flow into expression fields, scripts or HTTP request bodies. Each downstream node may evaluate those values with its own interpreter, so a single output can reach several sinks. Check which nodes accept model output as expressions, whether those expressions run in a sandbox and which credentials the workflow runner can reach.

Chat features that render through a template engine

Illustrative example: a chat product passes model replies through a server-side template before display, for example to apply branding or personalize greetings. Output that contains template expressions can then run on the server rather than being shown as text. Check whether the rendering path uses the model reply as data, whether user-supplied templates are ever compiled and whether the engine's sandbox is enabled and kept current.

How the exploitation probes send and judge prompts

The exploitation probes work by asking the model to produce text that contains an injection payload, then checking that text for the risky construct. A probe holds the crafted prompts, such as requests that would have the model write a Jinja template expression, a Python-style code fragment, or a SQL statement built around a payload. garak sends each prompt through a generator, which is the component that talks to your endpoint, and collects what comes back. For a text-to-SQL or template path, the question garak answers is narrow: did the model emit the dangerous construct at all? It does not run the SQL, render the template, or observe what your application does with the output.

Each probe runs with its recommended detectors under the default probewise harness, so you do not need to choose a detector to get a first result. By default garak makes 5 generations per prompt. If any attempt produces undesirable output, the probe is marked FAIL with a failure rate, which means one bad generation is enough to fail the probe. Each garak run writes a JSONL report that records every attempt and its evaluation, so you can find the exact output that triggered a failure and check whether the detector was right. Confirm the current defaults and detector mapping for the version you install, since these settings can be changed in configuration.

A PASS only means these payloads did not appear in the output under the prompts and detectors garak used. It does not show that the database, template engine or downstream service is safe. The application may still build queries by string concatenation, render user-influenced text through an unsafe template path, or accept a construct that garak's detectors do not match. Treat garak's result as evidence that the model's output was tested, and pair it with a review of how your code parses and executes that output, including parameterized queries, sandboxed rendering and allow-listed operations.

Probe choices and when each fits

This table compares the three named exploitation probes and the wider exploitation family, showing what each name suggests it targets and which application path it fits. Use it to choose a starting set, then confirm each probe's behavior in the source before you rely on a clean result. The main takeaway is that narrowing probes lowers run time and model cost, but it also narrows coverage of the rendering and query paths you actually operate.

Probe or optionWhat the name suggestsApplication path it fitsWhat to confirm before relying on it
JinjaTemplatePythonInjectionTemplate injection that reaches Python through Jinja syntaxModel output passed into a Jinja renderer for emails, reports, prompts or web pagesWhich Jinja environment the sample app uses and whether sandboxing is enabled
SQLInjectionSystemSQL injection through a system-level or executing pathModel output that builds or runs a query against a live databaseWhether your app runs generated SQL directly or through a parameterized, read-only layer
SQLInjectionEchoSQL injection checked by whether the payload is echoed backApps that return model-generated text into a SQL context or display SQL resultsWhat the detector looks for in the response and whether it matches your output format
Exploitation family (all probes)Broad injection coverage across template, code and SQL injectionEarly scoping when the app's rendering and query paths are not yet mappedWhich probes the family currently includes in your installed garak version
Probe selection by name or tagLimits a run to the named probesRepeat runs against one path after a fix or a prompt changeRun the probe list command for your version so you know exactly what runs
Generations per promptNumber of attempts per probe prompt, default 5Quick checks during development versus confirmation before releaseLower values reduce model cost and run time but can miss intermittent output
Wider probe setMore probes and attempts across categoriesPre-release review where injected output may reach several sinksExpect longer run time and higher model usage on hosted endpoints

Running the exploitation probes against your endpoint

This sequence installs garak, points it at the application endpoint that users actually reach, selects the exploitation probes, and produces a JSONL report you can review for SQL and template injection attempts. Each step ends with a check so you know the run is testing what you intended.

  1. Install garak in a clean Python environment

    Create a virtual environment on a host that runs Python 3.11 or newer, then install garak from PyPI with pip. The PyPI package requires Python 3.11 or newer, and the garak README describes the tool as developed on Linux and macOS, so confirm your host operating system before you start. Run the garak help command from the same environment. You are done when the command prints its usage text without import errors and the installed version matches the release you intend to use for the whole assessment.

  2. Write the REST generator configuration for the application

    Create a YAML file that uses garak's REST generator to call your application's chat or query endpoint, not the bare model API. Set the URL, HTTP method, headers for authentication, and the request body template so the user message lands where your application expects it. Use the response key path that your application returns, and keep secrets in environment variables rather than the file. garak's REST generator accepts plaintext or JSON responses, so match the response format your application produces. Check the configuration by sending one benign question with a short manual request, confirming the endpoint returns the same output shape the application uses in production, including any wrapper fields that garak must parse.

  3. Confirm garak receives the application's answer

    Run a single generation with a harmless prompt through the configured generator. The goal is to confirm that garak extracts the same text your users see, not a raw envelope, an error page or an authentication redirect. Compare the returned text against the application's own response for the same question. If the text differs, adjust the response key path or the request template and repeat. Keep this check in your runbook, because a changed response wrapper after an application release can silently cause garak to score empty or error output.

  4. Select the exploitation probes

    Choose the exploitation module's probes for the injection classes your application exposes: JinjaTemplatePythonInjection for template rendering, and SQLInjectionSystem and SQLInjectionEcho for query generation. List the available probes in your installed garak version, then pass only the ones that match your design, so the report stays focused on the paths you need to evaluate. Record the exact probe names and the garak version in your test plan so the run can be repeated and compared later. You are done when the selected probe list matches the plan and the run command reports those probes as loaded.

  5. Run the scan against the endpoint

    Start the scan with the generator configuration and the selected probes, leaving the default generation count of 5 per prompt unless your plan says otherwise. Keep the terminal output or run log so you can see which probes ran and whether errors occurred. Watch for repeated connection failures, rate-limit responses or empty outputs, since these make the results incomplete. The scan is finished when garak reports completion for each selected probe without unhandled errors.

  6. Open the JSONL report and check coverage

    garak writes a JSONL report with every attempt and its evaluation for the run. Open it and count the attempt records for each selected probe. If any probe has no attempts, the run did not reach that path, so check the generator configuration and the probe selection before drawing conclusions. Also check that the recorded prompts and responses match the application's behavior, which confirms the scan exercised the full endpoint. Keep the report with the run record, along with garak.log, which garak continues across runs for debugging.

  7. Review flagged attempts against the data path

    Read the attempts that the detectors marked as undesirable and trace each one to the system that would execute or render the output. A flagged SQL-like string matters only if the application passes model text to a database or query engine, and a flagged template expression matters only if a renderer evaluates it. Record which attempts reached a real execution or rendering step, since a probe hit that never leaves the model is a different finding. Confirm each conclusion by repeating the request against a non-production environment with the same code path before you report it.

Reading results without mistaking a pass for safety

A PASS from an exploitation probe only means that none of the attempts produced output the detectors flagged. It does not show that the application is safe. garak marks a probe as FAIL with a failure rate when any attempt produces undesirable output, and by default it makes 5 generations per prompt, so a FAIL tells you the model can emit injectable text and a PASS tells you only that the sampled attempts did not. Read the JSONL report for each attempt and its evaluation, not just the summary line, and record which probe, detector and generator produced each result. Confirm the attempt count and sampling settings for your run before comparing results across model versions.

A PASS on a bare model says little about the application's parser or template engine. The probes send prompts to the model and inspect what comes back, so they never exercise your SQL driver, your query builder, your Jinja environment or the code that decides whether an output is trusted. A model that never writes a stray quote or a {{ sequence can still be combined with user input in an f-string, a string-concatenated query or an unsandboxed render call. Treat the garak result as a statement about the model's output, and test the consuming path separately, using the same payloads through the real endpoint so the output travels through every layer your users would hit.

When a attempt fails, trace it to the code that consumed the output. Start from the generated SQL or template string in the report, then find where your application passes it to a database cursor, an ORM raw method, a template renderer or a shell. Confirm whether the code uses parameterized queries for values, whether the template engine runs in a sandboxed environment with the dangerous attributes blocked, and whether an allowlist limits the tables, functions and statements a model may request. These controls belong to the application team, who own the code and the database roles. Ask them to document the result of each check and rerun the failing probe after any change to that path.

Security and operational controls for the test itself

A garak run against a text-to-SQL or template path sends deliberately malicious payloads into live systems and writes them to disk. The controls below keep the test from becoming an incident of its own, and they apply whether the scan is run by your team or a partner.

Scan a staging endpoint

Point garak at a staging copy of the application, never production. Give the SQL execution path a read-only role or a disposable database seeded with synthetic data, so a payload that the model produces and the application runs cannot modify or delete real records. Confirm the role has no write grants, no access to other schemas, and no network route to systems you do not want touched.

Keep credentials out of reports

The REST generator configuration and the model client settings contain API keys and endpoint tokens. Store them in environment variables or a secrets manager, reference them from the YAML configuration, and never commit a populated file to version control. Check a sample of the JSONL and garak.log output after a first run to confirm no key or session token was echoed back by the endpoint.

Restrict access to payload output

The JSONL report records every attempt, including the generated SQL and template strings that the probes elicited. Those strings are attack payloads and may contain sample data from the application's prompts. Store reports in a restricted location, grant read access only to the team reviewing findings, and set a retention rule that your data governance policy approves.

Handle garak.log as sensitive

garak.log is continued across runs, so it accumulates debugging detail from every scan. Confirm what the log captures at your chosen verbosity, including prompts and responses, before sharing it in a ticket. Rotate or archive it between test cycles so old runs do not persist on a shared host.

Align scans with model and prompt changes

A scan result describes one model version and one system prompt. Rerun the text-to-SQL and template probes whenever the model, its serving configuration, the system prompt, or the query and rendering code changes. Keep a record that ties each report to a release identifier so a later finding can be traced to the build that produced it.

Define who approves each scan

Agree in writing who may start a scan, which endpoints are in scope, and who is notified if a payload reaches a live system. Name the owner of the staging database and the person who can stop the run. Confirm these roles with your security and data owners before the first scan, since the answers depend on your own change and incident processes.

Questions teams ask before running text-to-SQL and template tests

Can our own team run garak's SQL and template injection probes?

Yes. Your engineers can install garak from PyPI, which requires Python 3.11 or newer, and point it at a test endpoint using a short YAML configuration for the REST generator. Running the probes is the simple part. Interpreting results takes engineers who know the consuming code: a FAIL means the model produced output containing an injection pattern, but whether that output reaches a database driver, a template engine or a sanitizer, and whether any control stops it, depends on how your application handles the text. Teams without that context often misread both false alarms and real exposure.

What drives the effort of a text-to-SQL and template review?

Effort scales with the number of paths where model output is executed or rendered, the number of endpoints that expose those paths, and how much remediation the findings require. A single chatbot that writes queries against one read-only replica is a different job from a reporting assistant that feeds generated SQL into several services, or a document generator that renders model text through a Jinja template in a customer-facing flow. Each path needs its own input, its own expected behavior and its own review of the fix. Ask any partner to list the paths in writing before agreeing a price.

How long does a garak run against these probes take?

Run time depends on the model being tested, the generations setting (garak makes 5 generations per prompt by default), and which probes you select. A hosted model behind a rate limit will run far slower than a local model on a GPU host, and a broad probe selection multiplies everything. Because these factors vary so much, measure run time in a staging environment with a representative endpoint before you plan a schedule. Your team can then estimate full scans and reruns from its own measurements rather than from a generic figure.

What do we need to provide for a text-to-SQL and template test?

The work needs a staging environment that matches production closely enough to be meaningful, plus several inputs that only your organization can supply:

  • Staging access to the application endpoint and the model behind it, with a service account that has the same permissions as real users.
  • Sample prompts that reflect how users actually ask for data or documents.
  • Named code owners for each execution and rendering path who can explain what happens to model output.
  • A test database with realistic schema and synthetic data, so that injected queries can run without touching customer records.

Missing any of these usually adds time to the engagement rather than reducing the testing itself.

Is garak free to use for these tests?

Yes. garak is licensed under the Apache 2.0 license and developed in the NVIDIA GitHub organization, and its maintainers describe it as a free tool. The license covers the software itself. Your costs come from the infrastructure you run it on, the model endpoints you call (which may bill per token if hosted), the engineering time to configure and interpret runs, and any remediation work. Confirm the license terms and any dependency licenses with your legal team before adopting it in a regulated environment.

What does a partner add beyond running the probes?

A partner adds scoping, fixed-scope testing, remediation review and retest. Scoping identifies which execution and rendering paths exist and which ones matter most. Fixed-scope testing agrees deliverables and timelines in writing before work starts, so the outcome is defined in advance. Remediation review checks that proposed fixes, such as parameterized queries, read-only database roles, sandboxed template rendering or output validation, address the failure rather than only the test case. A retest then confirms the fixes hold. DeployOpen performs security testing and delivers findings with fixes and a retest, but it does not issue audit reports or certifications.

Which application designs most need these tests?

Any design in which model output is passed to something that interprets it deserves these tests. The most common cases are:

  • Text-to-SQL assistants that generate queries executed against a database.
  • Agents or workflows where a model writes code or commands that a runtime evaluates.
  • Applications that render model text through a template engine such as Jinja.

Applications that only display model text in a chat window are covered by different tests. Map your own data flow first, then confirm with the owning team which outputs leave the model and where they go.

Request flow from garak prompt to interpreter shows where model output becomes executable

The flow starts in garak, where a probe such as SQLInjectionEcho or JinjaTemplatePythonInjection creates a prompt and the REST generator sends it to the application endpoint. The model's reply is then handed to the application, which passes it to a SQL engine or template renderer that runs against the staging database used as the scan target. The detector reads the application's response and garak writes the result to the JSONL report. The key check is the trust boundary between model output and the interpreter, because that is where injected text gains meaning.

Model output crosses into the interpreter, and the detector only sees the application's response.

How DeployOpen scopes and delivers this test

DeployOpen approaches this test as a fixed-scope security engagement on the application that actually executes or renders model output, not on the bare model alone. We start by mapping which generated strings reach a database, a query builder or a template engine, then agree the probes, endpoints and evidence in writing before any testing begins.

How we scope

  • Map every path where model output reaches a SQL engine, template engine or code execution step in your application.
  • Identify the exact generator endpoint, including the system prompt, tool wrappers and any middleware between model and database.
  • Agree in writing which garak exploitation probes run, which detectors judge results, and what counts as a finding.
  • Confirm database and rendering test environments with read-only or disposable data, since probes send hostile input.

How we build

  • Write the garak REST generator configuration so probes reach the same request path your users trigger.
  • Run SQLInjectionSystem, SQLInjectionEcho and JinjaTemplatePythonInjection probes against the staging application.
  • Trace each failing attempt from the JSONL report back to the query or template call that received the output.
  • Test the application-side fixes, such as parameterized queries, read-only database roles and sandboxed template rendering.

How we hand over

  • Deliver the garak configuration files, run logs and JSONL reports with a plain-language summary of each finding.
  • Document the data flow, trust boundary and the fix recommended for each confirmed injection path.
  • Walk your engineering and security teams through the retest results and the remaining open items.
  • Leave a repeatable scan procedure that your own team can rerun after model or prompt changes.

How we support

  • Retest confirmed fixes against the same probe set and record the before and after results.
  • Ongoing support, upgrades and continuous testing are available as a retainer after the fixed-scope engagement ends.
  • Rerun the exploitation probes when you change models, system prompts, database schemas or template engines.
  • Confirm the garak version and probe set you will use with DeployOpen before each scheduled rerun.

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.