When a custom garak detector for your policy is worth building
Your application has a policy that the built-in garak detectors do not check, such as a forbidden phrase, a leaked internal identifier or a tool call the model should never make. A custom detector is the garak plugin that judges each model response against that policy and returns a verdict. It sits in the middle of the pipeline. garak is built from five plugin categories: probes, detectors, evaluators, generators and harnesses. A probe supplies the attack prompts, a generator sends them to your model or endpoint, and a detector decides whether the output is undesirable. The default probewise harness runs each probe with its recommended detectors, so a custom detector only runs when a probe is configured to call it, or when you wire it into a scan explicitly. Knowing this boundary tells you what a detector can and cannot fix: it changes how an existing attack is judged, but it does not create new attacks.
Reuse an existing detector when the policy you care about is a general weakness that garak already names, such as toxicity, data leakage or a known jailbreak success signal, and the probe that targets it already calls a sensible detector. Build a custom one when your rule is specific to your product: a string that must never appear in output, a customer identifier format, a refund action that requires approval, or a JSON tool call with forbidden arguments. Before writing code, list the policy rules your application owns and check which of them a current detector would judge correctly on your own sample outputs. Any rule with no matching detector, or where the existing detector gives obvious false results on your data, is a candidate. Confirm the exact detector names and their behavior in the garak user guide for the release you run, because detector coverage changes between versions.
Choosing string matching, a classifier or a judge model
This table compares three ways to build a garak detector: string or pattern matching, a classifier, and a judge model. Read each row as a decision: match the approach to the kind of policy you are checking, then confirm the failure modes and operating costs before you commit. The main takeaway is that the simplest approach that fits the policy is usually the easiest to verify and keep false positives low.
| Approach | Best fit | Main failure mode | Cost and operational drivers | What to confirm |
|---|---|---|---|---|
| String or pattern matching | Exact forbidden phrases, internal hostnames, account formats, or leaked identifiers with a known shape | Misses paraphrases and encoded or translated leaks; over-matches common substrings | Low run cost; effort goes into maintaining patterns and test cases | Pattern coverage against your own sample of real and synthetic outputs |
| Classifier | Semantic policy categories such as self-harm, harassment or disclosure of a named topic | Drifts on domain language it was not built for; threshold choice shifts results | Needs a model to host and version; compute and latency scale with output volume | Label set, training data source, and how the vendor documents its evaluation |
| Judge model | Nuanced policy questions, such as whether a reply gives actionable guidance or reveals internal policy | Inconsistent verdicts across runs; judge can be fooled by the same tricks it is judging | Per-attempt model calls add cost and time; rubric and judge version must be recorded | Rubric wording, judge model identity, sampling settings, and whether results repeat |
| Hybrid (string gate, then classifier or judge) | Cheap checks handle clear cases; a model handles the ambiguous remainder | Two detectors can disagree, and the logic that combines them is easy to get wrong | Adds a second component to version and test; saves model calls on clear cases | Routing rules and how disagreements are logged and reviewed |
| Tool call or structured output check | Policies about which function was called or which fields appear in a JSON response | Breaks when the output format changes or the app uses a different tool name | Parsing logic to maintain; low runtime cost | Output schema of your application and how tool calls appear in captured responses |
Build and register a custom detector step by step
This sequence takes a policy from a written definition to a detector that loads in garak, scores known examples correctly, and appears in a scan report. Each step ends with a check so the team knows whether to move on.
Install garak and confirm the environment
Install garak from PyPI into a clean virtual environment on Python 3.11 or newer, since the PyPI package requires that version or later. Run the garak command-line help and a short scan against the blank generator to confirm the install works. Record the installed version so later results can be traced to the same release. Done means the help output and the blank-generator run both complete without errors.
Define the policy and its examples
Write the policy in one sentence that a reviewer could check, such as a forbidden phrase, a leaked internal identifier, or a tool call that should never be made. Collect positive examples, meaning outputs that violate the policy, and negative examples, meaning outputs that are acceptable but look similar. Include near-misses in the negative set, such as a product name that resembles an internal code. Done means you have a written policy and a labeled sample file that a second person has reviewed.
Choose the detector approach for the policy
Pick string matching for fixed phrases or identifiers, a classifier for paraphrased content, or a judge model for policies that depend on meaning or context. Structured policies such as tool calls are often best checked by parsing the output. Record the reason for the choice, because the false-positive review in a later step depends on it. Done means the approach and its reasoning are written next to the policy definition.
Subclass the base detector and implement detection
Create a Python module in your garak plugin path and subclass the detector base class that fits your approach, reading its interface in the garak user guide and the plugin source for the installed version. Implement the detect method so it returns one score per output, where a higher score means the policy was violated. Keep configuration such as phrase lists in the class or a separate file, not in code paths that need secrets. Done means the module imports without errors in the same environment.
Register the detector with a probe
Add your detector's identifier to the recommended detectors of a probe that produces the attack the policy targets, or to a custom probe you are building for this purpose. Confirm the identifier matches the module and class name exactly, because a mismatch fails silently or raises an error depending on the path. Done means garak lists the detector when you query its plugin list and the probe reports it in its detector configuration.
Test against known-bad and known-good samples
Run the detector directly on your labeled positive and negative examples, outside any model scan, and tabulate true positives, false positives, true negatives and false negatives. Review every false positive and false negative and adjust the detector or the examples, then rerun. Done means the detector flags every positive example and clears every negative example you have agreed on, or the remaining gaps are written down with an owner.
Run a test scan and confirm the report
Run garak with the blank generator or a non-production endpoint, selecting the probe that uses your detector. Open the JSONL report and confirm your detector's name appears in the evaluation of each attempt and that scores match your direct test. Keep the garak.log file, since it records errors that the report does not show. Done means the report contains your detector's results for every attempt and the log shows no unhandled errors.
How to measure false positives before trusting a detector
Before a custom detector drives any FAIL result, measure how often it is wrong. Build a labeled set of model responses, run the detector over every item, and record each false positive (the detector flags a response that is acceptable) and each false negative (the detector misses a response that breaks the policy). Keep the set small enough to label carefully, and include the awkward cases on purpose. For a forbidden-phrase detector, the set should contain refusals that quote the forbidden phrase, policy text that restates the rule, and ordinary sentences that mention a product name or account number. All examples in your own set should be labeled as illustrative until your team has reviewed them against your policy.
The most common source of inflated FAIL results is a detector that flags harmless text. A refusal such as "I can't share the account number" may contain the trigger word, and a string matcher will count it as leakage. A detector that matches a leaked identifier pattern will also match a sample identifier from documentation. Each false positive turns a passing probe into a FAIL, and because garak marks a probe as FAIL when any of its attempts produces undesirable output, one noisy detector can fail an entire probe family. Count false positives separately from false negatives, since they push your numbers in opposite directions and call for different fixes.
Run the same labeled set against each detector version and record precision and recall in a table that stays with the detector code. When you change a pattern, rerun the set before the change reaches a scan. Then compare scan results across runs using the JSONL report and the results views in the garak user guide, so that a shift in FAIL rates can be traced to the detector change or to the model. Do not state an accuracy target from this page. Agree the acceptable false positive and false negative rates with your security and product owners, and confirm how your chosen garak release reports detector results before relying on any comparison.
Security risks in custom detector code and test data
A custom detector is code that runs inside your scan environment and touches the same responses, logs and reports as the model under test. The risks below come from that position: what the code can execute, what it writes down, and what it sends to other services.
Detector code runs in the scan environment
A garak detector is Python that loads and runs in the same process as the scan, so a careless import, a network call or a file write inside it runs with the scanner's permissions. Treat detectors like any other internal code: review them, keep them in version control, and run scans from an account that can reach only the target endpoint and the report storage. Ask who approves a new or changed detector before it runs against production.
Sensitive identifiers in reports and logs
Each run writes a JSONL report of every attempt and its evaluation, and a garak.log file that continues across runs. If your detector matches a customer ID, account number or internal project name, that value can appear in both files. Mask or hash matched values in the detector output, check the report and log for them after a test run, and restrict who can read the scan directory.
garak READMETest data containing real customer records
Detectors need examples of both a leak and a safe answer, and the fastest source is often a production transcript or a support ticket. Those examples carry personal data into test files, repositories and reports. Use synthetic identifiers that follow the same format, keep any real samples in an approved store, and record who created each test case so the data can be removed when the detector is retired.
Judge model calls sending responses out
A judge-based detector sends each model response to a second model to score it. If that judge is a hosted API, the target's outputs, which may contain customer data or internal policy text, leave your environment. Decide before the build which judge endpoints are approved, confirm the provider's data handling terms in writing, and prefer a judge hosted inside your own infrastructure for sensitive applications.
Secrets stored in config files
Generator and judge settings often need API keys, and it is tempting to place them in the YAML configuration next to the detector. Those files get copied into tickets, shared repositories and scan reports. Read credentials from environment variables or a secrets manager at run time, keep configuration files free of key values, and rotate any key that was ever committed.
Detector changes altering comparisons
A change to a detector's pattern, threshold or judge prompt can shift the failure rate without any change in the model. A drop may look like an improvement, and a new failure may look like a regression. Version each detector, record its version in the report, and rerun a fixed set of known-good and known-bad examples before using the new version for comparisons.
Questions teams ask before writing a custom garak detector
How much effort does a custom garak detector take?
Effort depends mainly on how precisely the policy can be defined. A forbidden phrase or leaked identifier that follows a fixed pattern can be checked with a short string or regular expression rule, and most of the work is in the test cases. A policy such as "the assistant gave medical dosing advice" needs a classifier or judge model, labeled examples to calibrate it, and repeated false positive review. The main drivers are policy complexity, the amount of labeled data you already hold, and which judge model you choose. Ask any partner to split their quote into policy definition, detector build, labeling, and false positive testing so you can see where the effort sits.
Can our internal team build a custom detector without outside help?
Yes, for simple rule-based detectors, a team with Python experience and a clear policy can usually build one using the plugin structure in garak's documentation at docs.garak.ai. Outside help is more useful when the policy needs legal or domain interpretation, when a judge model must be calibrated, or when the detector has to be reviewed as security evidence. Garak is free and licensed under Apache 2.0, so the tool itself carries no license cost. Your real costs are staff time, test infrastructure and review, and these are the items to size before deciding.
What does the work need from our team?
A detector is only as good as the policy behind it, so the work needs people who can state that policy precisely. Typically this means:
- A policy owner who decides what counts as a violation and resolves borderline cases
- Labeled examples of compliant and non-compliant outputs, including near misses
- A test environment with a model or application endpoint where the detector can run against known outputs
- Access to the application's system prompts and tool definitions, so the detector matches real output formats
Ask your partner which of these they expect you to provide and which they will create.
How long should we plan for review and false positive testing?
Plan for review and false positive testing as a separate phase, because it often takes longer than writing the detector. Run the detector against outputs you already know are safe and outputs you know violate the policy, then record every disagreement. Each disagreement either fixes the rule or changes the policy definition. Duration depends on how many examples you can label, how many reviewers agree on the policy, and how often the application changes. Ask for a fixed review plan with a stated number of test rounds in any written scope, since no general duration applies to every policy.
Does a judge model add cost and data exposure?
Yes, a judge model adds two kinds of cost. It adds inference cost, because each evaluated output requires another model call, and that cost recurs for every scan run. It also adds data exposure when the judge is a hosted service, because scanned prompts and model responses are sent to that provider. If the outputs contain customer data or regulated information, the judge should run inside infrastructure you control. Confirm the hosting, retention and logging terms of any judge model before you approve it, and record which model and version produced each verdict so results can be compared later.
When should we reuse an existing garak detector instead?
Reuse an existing detector when it already checks the behavior you need and its false positive rate is acceptable for your policy. Garak ships with a range of detectors that a probe can call by default, and the probewise harness runs each probe with its recommended detectors. Write a custom detector only when no existing detector matches your policy, or when a built-in one flags too much or too little for your application. Before you build, run the existing detectors against your own labeled examples, because that test shows whether a custom detector is needed at all.
Keeping custom detectors working across garak releases
A custom detector is code that depends on a garak release, so treat it like any other dependency. The current release is v0.17.1, published on 16 October 2026. Pin the garak version your detector was tested against in your project files, keep the detector module and its tests in version control, and record the pinned version next to every report it produces. Before you move to a newer release, install it in a separate environment, run your detector's test suite, and confirm the detector still loads under the new plugin interface. Check the garak releases page for the changes listed for each version before you decide when to upgrade.
Scores can move after an upgrade for reasons unrelated to your detector. Harness defaults, probe changes, generation settings and the way results are aggregated can all shift a failure rate, so a drop or rise in a scan does not by itself show that the detector changed. Detector drift is the case where the same model output receives a different verdict. To separate the two, run the old and new garak versions against the same saved transcripts, or call the detector directly on them. If the verdicts match, the score change came from elsewhere in the pipeline. If they differ, the detector or its dependencies changed and you need to find out which.
Keep a fixed, labeled test set of model outputs as a regression check. Include examples your policy should flag, examples it should pass, and the borderline cases your team argued about when writing the rule, each with the expected verdict and a short note on why. Run this set in CI on every change to the detector and on every garak upgrade, and fail the build when any verdict changes without a recorded decision. Store the set alongside the detector so it is reviewed with it. Confirm with your own team how often the set should be extended, since new false positives found in production scans are the most useful additions.
How DeployOpen scopes and delivers custom garak detectors
DeployOpen approaches a custom garak detector as a scoped piece of work: first the policy and the evidence it must produce, then the detector, its false positive checks and a handover your team can run. Engagements are fixed-scope, with the scope, deliverables and timelines agreed in writing before work starts.
How we scope
- Write down the exact policy the detector must enforce, such as a forbidden phrase, leaked identifier or unauthorized tool call, with examples of what counts as a failure
- Agree which detector approach fits each rule (string matching, classifier or judge model) and the cost and review effort each one adds
- Confirm the target endpoints, the probes the detector will attach to, and the report evidence your compliance or security reviewers expect
How we build
- Implement the detector as a garak plugin in the client's repository, with the matching logic, configuration and any labelled test cases kept under version control
- Measure false positives and false negatives on a labelled set of benign and violating responses, then tune thresholds or patterns until the agreed results are met
- Run the detector against the target model or application in a controlled environment, and confirm it writes the expected entries to the JSONL report
How we hand over
- Deliver a written guide covering how the detector works, its known limits, how to add new patterns and how to read its results in garak reports
- Provide the labelled test set and the false positive review notes, so your team can rerun the checks after changes to the policy or the model
- Walk your engineers through running the detector in your own environment, so the code and its test evidence stay under your control
How we support
- Support after handover can be provided as a retainer covering updates when garak releases change plugin interfaces or report formats
- Retests after policy changes, new model versions or new application features can be scoped as additional fixed-scope work
- Ask any provider to confirm in writing who maintains the detector code, how changes are reviewed and what support terms apply

