Testing LangChain and LangServe applications with garak

garak tests LangChain chains and agents in process through its LangChain generator, or over HTTP through the LangChain Serve generator. This page covers which method fits your app, the setup sequence and what to verify.

On this page

Testing LangChain and LangServe applications with garak

A scan of the bare model tells you how the model behaves, but it does not tell you how your application behaves. A LangChain chain or agent adds a system prompt, retrieval over your documents, tool calls and output handling, and each of those layers can widen or narrow what an attacker can reach. garak ships a LangChain generator (LangChainLLMGenerator) for testing a chain in process, and a LangChain Serve generator (LangChainServeLLMGenerator) for systems and models served over HTTP through LangChain Serve. Either way, the probes travel through the same path your users take, so the results describe the application rather than the model alone. garak is a free, command-line tool licensed under Apache 2.0 and developed in the NVIDIA GitHub organization. It installs from PyPI with pip and requires Python 3.11 or newer, so the scanning host needs that interpreter and the LangChain packages your application imports.

The first decision is which generator fits your deployment. The in-process generator suits a team that can import the chain into the scanning environment and wants to test a version of the code before it is deployed. The LangChain Serve generator suits a chain already running as a service, because the scan goes through the same endpoint, authentication and middleware that production traffic uses. Confirm the exact configuration keys and the supported LangChain and LangServe versions against the generator source code in the garak repository before you write the configuration, since those details change between releases. Ask whether the chain you are testing is the one users reach, including any retrieval index and tool permissions, because a scan of a staging copy with different tools will report different risks.

Plan the test as an application test from the start. Record which retrieval sources, tools and credentials the chain can use during the scan, and whether those are the production values or safe test substitutes. Scans that trigger real tool calls, such as sending email or writing records, need explicit approval and a sandboxed target. Keep the garak report, which is written as a JSONL file for each run along with the garak.log file, together with the chain version and configuration, so that a later rescan can be compared with the same target. Findings that involve retrieved content or tool use usually need fixes in the chain, not the model, so give the report to the team that owns those components.

Choosing in-process or over HTTP

The LangChain generator, LangChainLLMGenerator, loads a chain or agent object directly inside the same Python process that runs garak. garak sends each probe prompt to that object and reads the returned output, so the scan runs against the code you wrote without a web server, a network hop or a separate deployment. This makes it the quickest way to iterate on prompt templates, retrieval settings and tool wiring during development, and it fits a CI job that builds the application from source on each change.

  • Requirements: garak and the application's dependencies must install in one Python environment, so the team owns that environment and its version pins.
  • Exposure: the scan reaches whatever the chain object exposes in code, including tools and retrievers it loads, but not the API gateway, authentication layer or reverse proxy in front of it.
  • Secrets: model and tool credentials are read by the application process in the test environment, so those keys must be scoped and kept out of logs.
  • Speed: there is no HTTP layer to add latency or rate limiting, which keeps development loops short.
  • Limit: behavior can differ from a deployed build when configuration, environment variables or infrastructure differ.

Before relying on this mode, confirm which chain type your application uses and that the generator constructs it the same way your service does.

What you need before the first scan

A LangChain or LangServe scan depends on four things lining up: a Python environment that can run garak, a working chain or endpoint to test, credentials the chain already uses, and a network path from the scanner. The test environment has to be set up so that a scan exercises the application without touching live customer data.

Python environment and garak install

garak is installed from PyPI with pip, and the PyPI package requires Python 3.11 or newer. Check the interpreter version on the scanner host before anything else, and install garak into a virtual environment so its dependencies stay separate from the application's own packages. Confirm the installed release with the garak command, then confirm that the LangChain generator and LangChain Serve generator files in your installed version match the source files for that release, since class names and parameters can change between versions. The garak project is developed on Linux and macOS, so plan for those hosts first.

garak on PyPI

Access to the chain or LangServe endpoint

For an in-process scan, the scanner host must be able to import the chain as a Python object, which means the application's packages and its configuration must be present in the same environment. For an HTTP scan, the LangServe endpoint must be reachable from the scanner with the routes garak will call. Ask the application owner which chain or route is exposed to users, because a scan should target the same path that real users reach, including any agent tools and retrieval steps behind it.

Model credentials the chain uses

The chain calls a model with its own credentials, and garak does not replace them. Confirm which model provider, deployment and API key the chain reads, and whether those keys are scoped for testing with rate limits and spending caps. Store them in environment variables or your secrets manager rather than in a garak configuration file that may be copied into reports or tickets. Also confirm which tools the agent can call with those credentials, since a probe that triggers a tool call may act on a real system.

Network paths from the scanner host

The scanner needs outbound paths to the model provider or self-hosted model server, and inbound or internal paths to the LangServe endpoint, retrieval store and any tool APIs the chain uses. Check firewall rules, proxy settings, DNS and TLS trust stores on the scanner host, because failures here often look like model errors. If your organization blocks outbound traffic to hosted APIs, confirm whether the chain can reach its model from the scanner's network segment at all.

Test environment without production data

Run the first scans against a staging copy of the application with a test vector store, a seeded document set and mock or sandboxed tools. Prompts sent by garak, along with the chain's responses, may be written to the JSONL report and garak.log, and retrieval results may appear in those files. Ask the application owner to confirm that no customer records, personal data or live credentials are present in the indexed documents or tool backends, and set retention and access rules for the report directory before the first run.

garak user guide

How to configure the LangChain and LangServe generators

This sequence takes a team from a clean garak install to a scan that sends probes through a LangChain chain or LangServe route, so the results describe the whole application rather than the bare model.

  1. Install garak in a dedicated environment

    The engineer running the scan installs garak from PyPI with pip into a virtual environment running Python 3.11 or newer, since the PyPI package requires that version. Garak is developed on Linux and macOS, so the scan host should be one of those. Confirm the install by running the garak command-line help and checking that the version matches the release your team has chosen to standardize on. Record the version in the scan notes, because later results should be compared against the same release.

  2. Identify the chain or route under test

    Before touching garak, the application owner and the security engineer agree which object is being tested. For LangChain, that is the chain or agent object that wraps the prompt template, retriever and tools. For LangServe, it is the HTTP route that exposes that runnable. Write down the module path or route name, the input schema the application expects, and which tools and retrievers it can call. A scan that targets the raw model would skip prompt templates and tool permissions, so this inventory defines what the results can and cannot claim.

  3. Configure the LangChain or LangServe generator

    Choose the generator that matches the deployment. The LangChain generator (LangChainLLMGenerator) runs the chain in the same Python process as garak, so the chain's code and dependencies must be importable from the scan host. The LangChain Serve generator (LangChainServeLLMGenerator) calls a system served through LangChain Serve over HTTP. Set the chain or endpoint reference in the generator configuration, and pass any model or runtime options through the generator's options block so they match production. Keep the configuration in a file under version control, because the settings define what was tested. Confirm the generator name and option keys against the generator source code linked from this page before the first run.

  4. Confirm the generator reaches the application

    Run a very small probe selection first, such as one probe family with its default detectors, and keep the generation count low for this check. The goal is to prove the generator loads the chain and returns text from it, not to measure risk. Open the JSONL report and the garak.log file. The report should contain prompts and responses that look like output from your chain, including the system prompt or template wording where it appears, and the log should show no import or connection errors. If responses read like a generic model with no application context, stop and check the chain reference before going further.

  5. Verify that results reflect chain behavior

    Use a short, deliberate probe that depends on the application layer, such as a prompt that asks the application to reveal its template or to call a tool outside its allowed set. Compare the response with what the application does when a normal user makes the same request through its own interface. The security engineer should confirm that the answer came through the chain, including retrieval or tool steps where those exist. Save this comparison with the scan record, since it is the evidence that the test covers the application rather than the bare model.

  6. Widen the probe selection deliberately

    Once the small run shows the generator is reaching the application, expand the probe list to the families that match the application's exposure, such as prompt injection for retrieval-augmented flows and data leakage for applications with private documents. Keep the generation count at the default of 5 per prompt unless the team has a documented reason to change it, and note any change in the configuration file. Run the wider set and review the FAIL results with failure rates in the report. Each expansion should be a separate, recorded run so that changes in results can be traced to changes in probes rather than the application.

  7. Store the configuration and scan record

    Save the generator configuration, the garak version, the probe list, the report and the log together in the team's repository or evidence store. Confirm that a second engineer can rerun the same configuration on the same chain and get comparable output, allowing for normal model variation. This record is what makes later scans comparable after the chain, prompts or tools change, and it gives reviewers a clear link from each finding to the application version tested.

How a garak scan reaches retrieval and tools

The scan starts on the scanner host, where garak runs its probes. The LangChain path keeps the chain in the same process through the LangChainLLMGenerator, while the LangServe path sends each prompt over HTTP through the LangChainServeLLMGenerator to a server you run. In both cases the probe reaches the prompt template, retrieval step, tools and only then the model provider, so the findings describe the whole application. Check where the trust boundary sits, which credentials cross it, and whether retrieval and tool calls are exercised, not just the model.

garak reaches the chain through two generators, then retrieval, tools and the model.

Why a chain test differs from a model test

A scan of a LangChain chain or LangServe endpoint measures the application you ship, not the model underneath it. The prompt template, retrieved documents, tool permissions and output parser decide what text reaches the model and what the model is allowed to do with its answer. A probe such as prompt injection can succeed because a retrieved page or a tool's returned text carries instructions the model then follows, even when the same model resists the same probe sent directly. Retrieval and tools open paths that a bare model scan never exercises, so a clean bare-model result does not certify the application.

Pair every chain scan with a bare model baseline run against the same underlying model, with the same probes and generation settings. If the baseline fails, the weakness sits in the model or its serving layer and the chain is inheriting it. If the baseline passes and the chain fails, the cause is in the application: the template that concatenates untrusted text, the retriever that admits attacker-controlled content, or a tool that acts without a check. Confirm with your engineering team which settings were fixed between the two runs, including the model name, temperature and system prompt, so that differences in the report can be attributed to the chain and not to configuration drift.

Decide before the first run which chain components are in scope and who owns each one. Ask the application team to document the retrieval sources, the tools the agent can call and the credentials each tool uses, because these define the attack surface your probes will reach. Verify with the team that the endpoint behaves the same way for scanner traffic as for users, since a chain that calls different tools or memory stores in test mode will produce a report about a different system. Record the garak version used for each run, as described in the garak report section of this page, so that a later rescan is compared against the same baseline.

Mapping chain components to what garak tests

This table maps each part of a LangChain or LangServe application to the garak probe families that exercise it and the fields in the JSONL report where the result appears. Use it to decide which probes to select for each component, then read the report by component rather than as a single pass or fail for the model.

ComponentWhat garak exercisesEvidence in the JSONL report
Prompt templatePrompt injection and jailbreak probes sent through the chain's input variables, to see whether user text overrides the system instructionsAttempt prompts and outputs per probe, with the detector verdict showing whether the template held
Retriever or document sourceIndirect injection and data leakage probes, to test whether retrieved text can steer the model or expose content it should not revealAttempts that contain retrieved-style content, with detector results indicating whether the reply followed the planted instruction
Tool or agent actionProbes for unsafe tool use and injected instructions that try to trigger calls the application should refuseOutput records showing requested actions, which you match against your own permission rules
MemoryMulti-turn probes that try to carry an attack across turns or extract earlier conversation contentAttempt sequences grouped by probe, so you can check whether later turns changed the outcome
Output parserProbes that try to break structured output or smuggle payloads through formatting such as markdown or encoded textRaw generations alongside detector outcomes, which show what reached the parser
ModelBaseline jailbreak, toxicity and hallucination probes run against the underlying model for comparisonPer-probe failure rates, which you compare against a direct model scan to see what the chain added or removed

Securing the test setup itself

A garak scan against a LangChain or LangServe application sends real prompts through your chains, retrieval and tools, and writes results to disk. The test rig therefore needs the same controls as the application it probes. The cards below cover credentials, endpoint exposure, tool side effects, stored evidence and the data used for testing.

Keep API keys out of config files

Scan configs are easy to copy into tickets and repositories, so keys for the model provider and any LangServe gateway belong in environment variables or your secrets manager, not in the YAML or shell history. Check that the scan runner reads keys at launch, that the config committed to version control contains only variable names, and that keys are rotated after any shared scan run. Ask who can read the runner's environment, because anyone with shell access to that host can read its keys.

Restrict LangServe endpoints used for testing

A LangServe route exposed for scanning is still a live chain. Bind the test deployment to an internal network address or a private gateway route, require authentication on every route, and avoid exposing routes that are only needed for development. Confirm which chains, retrievers and tools are reachable from the test route, and whether the test identity has the same permissions as a real user.

LangChain Serve generator source

Disable or sandbox tool side effects

Adversarial prompts often try to make an agent call tools, so a scan can trigger real emails, tickets, database writes or payments. For the test run, point tools at staging services, read-only credentials or mock backends, and remove write permissions the scan does not need. Record which tools were enabled during each run, since a finding that only reproduces with live tools needs a different remediation.

Protect garak.log and JSONL reports

Each run writes a JSONL report of every attempt and a garak.log file that keeps growing across runs. Both can contain the probe prompts, model outputs and any document text a retriever returned, which may include personal or confidential data. Store them in a restricted directory with access logging, set a retention period agreed with your security team, and encrypt them where the host storage is shared. Confirm that the log level does not echo secrets from the environment.

garak user guide

Test against non-production data

Retrieval-augmented chains return whatever the index holds, so a scan against a production vector store can expose real customer records in the report. Build a test corpus with synthetic or de-identified documents that match the structure of production content, and load it into a separate index. Ask the application owner to confirm that the test index, the test chains and the test identity never touch production records.

Common failures when scanning LangChain apps

This table lists the failures teams most often hit when pointing garak at a LangChain or LangServe application, with the likely cause and a fix for each. Read each row as a checklist item to confirm in your own target environment before you trust the results of a scan.

FailureLikely causeFix to confirm
Generator import errorThe installed LangChain packages do not match the version garak's LangChain generator was written against, or the optional dependency is missing from the garak environment.Install garak in a clean Python 3.11 or newer environment, then install the LangChain components your chain needs and confirm the generator loads before a full scan.
Timeouts on the LangServe endpointThe chain is slow because of retrieval latency or large context, and the default request timeout is shorter than a typical chain response.Measure one chain call by hand, raise the timeout in the generator configuration, and lower parallel attempts so the server is not overloaded.
Authentication failures on LangServeThe endpoint sits behind an API key, bearer token or gateway policy that the scan configuration does not send, so requests return an auth error that looks like a model refusal.Send one authenticated request with the same headers garak will use, then check that the scan log shows successful responses rather than error bodies.
Scans that trigger tools with side effectsAgents and tool-using chains can send email, write records or call production APIs when probes ask them to act on injected instructions.Run scans against a staging deployment with sandboxed tools, read-only credentials and test accounts, and confirm no production system is reachable from the chain.
Reports that show model-only behaviorThe scan targeted the underlying model directly, or the chain's system prompt, retrieval step and tool wrapper were bypassed, so the results say little about the application.Confirm the generator points at the chain or agent endpoint, then check report entries for evidence of retrieved context or tool calls before treating the results as application findings.
Rate limits from the model providerThe chain calls a hosted model API, and each garak attempt multiplies provider requests, so the provider returns throttling errors partway through a run.Check the provider's rate limits for your account, reduce parallelism, and rerun failed probes separately. Confirm the limits with the provider, since they vary by account and model.

Questions teams ask before scanning a LangChain app

Can our team run garak against a LangChain app without outside help?

Yes, if you have engineers who can install a Python package, write a small configuration for your endpoint, and read the results. garak is a command-line tool installed from PyPI with pip, and the package requires Python 3.11 or newer. The harder part is not the install but deciding what to test. A LangChain application has prompts, retrieval, tools and authentication, and a useful scan needs someone who knows which of those the attacker can reach. Teams often start in-house for a single chain and bring in a partner when the scope grows to agents, multiple endpoints or a formal review.

What makes a LangChain scan take more or less effort?

Effort follows the shape of the application, not the number of prompts garak sends. The main drivers are:

  • The number of chains and agents you expose, since each entry point needs its own target definition.
  • The number of tools the agent can call and what each tool can change or read.
  • The retrievers and data sources behind the chain, including whether retrieved content is trusted.
  • Endpoint authentication, such as API keys, session tokens or SSO, which determines how garak authenticates.
  • Whether the app runs in process through the LangChain generator or over HTTP through the LangChain Serve generator.

Each added tool or auth scheme adds configuration and verification work.

How long does setup take in a typical environment?

Setup time depends on your environment more than on garak itself. Installing garak is quick on a workstation with Python 3.11 or newer. The time goes into access, staging and configuration: getting a non-production endpoint, confirming which chains and tools are live there, wiring authentication, and checking that a small test run returns sensible output. Air-gapped hosts, strict change control and endpoints that sit behind a gateway usually add the most time. Ask any provider for a schedule that lists these steps separately and states which ones depend on your teams.

What must our team provide before a scan starts?

Before a scan starts, the team usually needs to provide:

  • Test access to a staging or pre-production copy of the chain, agent or LangChain Serve deployment, not production.
  • Credentials for a test user and any service accounts the tools use, scoped to test data.
  • A description of the tools, retrievers and data sources, so the scope matches what the app can actually do.
  • Network routes from the machine running garak to the endpoint, and approval for the test traffic from the owners of the gateway and logs.

Agree in writing who can change the system during testing and how findings will be handled.

Is garak free to use, and what does the Apache 2.0 license allow?

garak is licensed under Apache 2.0 and is developed in the NVIDIA GitHub organization, and its maintainers describe it as a free tool. Using it to scan your own LangChain applications does not require a license fee. Your legal team should still read the license text and confirm the terms for your use, including any modifications you make. Your costs come from the people running the scans, the model calls the scans generate, and any outside help you buy.

Does a garak scan count as compliance evidence?

No. A garak scan is a test of how your application responds to adversarial input. It produces a JSONL report of attempts and their evaluation, which can support your own assessment, but it is not an audit, attestation or certification. Independent auditors and certification bodies decide whether controls meet a framework. Scan results become more useful as evidence when the scope, configuration, version and dates are recorded and the test is repeated after changes.

What do teams usually check first in the scan results?

Start with the probes that match your exposure: prompt injection and data leakage for chains that retrieve documents, and tool misuse for agents that can act. Review the failing attempts in the JSONL report rather than only the summary, because a failure in a tool path matters more than a failure in plain chat. Confirm that the run used the same chain, configuration and version you deploy, since a change to a prompt or tool can shift results. Then decide which failures need a fix and which need a retest.

How DeployOpen scopes and delivers a LangChain scan

DeployOpen approaches garak testing of LangChain and LangServe applications as a written, fixed-scope engagement that starts from the chains, agents, retrievers and tools your users reach, not only the underlying model. The work covers scoping, configuration, testing, documentation and handover inside your own infrastructure, with ongoing support available as a retainer.

How we scope

  • Inventory the chains, agents, retrievers, prompt templates and tools that a scan must reach, and record which are in process and which sit behind LangServe routes.
  • Agree which probe families and attack categories apply to your application's exposure, such as prompt injection through retrieved documents or tool misuse.
  • Confirm the Python version, garak release and network paths, and write the scope, deliverables and timeline into a document signed before work begins.

How we build

  • Configure the LangChain generator or the LangChain Serve generator against a non-production instance, with credentials held in your secrets store.
  • Build repeatable garak configuration files that pin probes, generations and detectors so that each run can be compared with the last.
  • Test the application end to end, including retrieval and tool calls, and record every finding with its JSONL report and garak.log output.

How we hand over

  • Deliver a findings report that separates prompt, retrieval and tool weaknesses, with reproduction steps taken from the scan output.
  • Document the run configuration, the generator settings and the commands your team needs to repeat the scan without DeployOpen.
  • Walk your engineering and security teams through the results and agree which fixes are yours and which need a retest.

How we support

  • Retest agreed fixes against the same configuration so that before and after results are directly comparable.
  • Plan rescans when chains, prompts, models or the garak release change, and confirm what a version upgrade may shift in scores.
  • Offer ongoing support, upgrades and continuous testing as a retainer, priced separately from the fixed-scope engagement.

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.