Customizing local detection
How to change what Shield detects and how strictly, from one sensitivity switch to your own phrases, patterns, categories, models, and LLM checks, per message source and per wrapper.
The options below apply to local detect and detectAsync from @zeroleaks/shield/local, and to local detection inside wrappers. The hosted API uses its release model and rule configuration; these local tuning options do not change its thresholds or rule layer.
The SDK exposes tuning options for every check Shield runs. This page lists them from simple presets to custom detectors, with links to the full reference.
How strict
sensitivity controls how readily text is classified as an injection:
detect(text, { sensitivity: "strict" }); // catch more, accept more false positives
detect(text, { sensitivity: "permissive" }); // flag only clear attacks| Value | Reported risk | Classifier threshold |
|---|---|---|
"strict" | low and above | 0.35 |
"balanced" (default) | medium and above | the model's own, 0.5 |
"permissive" | high and above | 0.75 |
For finer control, set these options individually. They take precedence over the preset:
threshold: the lowest risk reported,"low","medium","high", or"critical".classifier:{ threshold, highThreshold }for the built-in classifier's probability cut-offs, orfalseto turn it off and keep only patterns.
What counts as an injection in your application
denyPhrases: phrases that should always be flagged in your application, such as the name of an internal override command. They match case-insensitively with any spacing, in the text as written and after normalization, and are reported as categorydeny_phrase, high risk.customPatterns: regular expressions with your own category and risk, for anything a phrase list can't express.allowPhrases: phrases removed from the input before scanning, for legitimate text that trips detection in your domain. The rest of the input is still scanned.
detect(text, {
denyPhrases: ["enable maintenance override"],
customPatterns: [{ category: "internal_codes", regex: /\bOVR-\d{4}\b/, risk: "high" }],
allowPhrases: ["for research purposes only"],
});Which categories
Each finding has a category. excludeCategories drops categories you don't want, and includeCategories keeps only the ones you list:
// Only care about prompt extraction and the classifier's verdict
detect(text, { includeCategories: ["prompt_extraction", "classifier"] });| Category | What it covers |
|---|---|
instruction_override | "Ignore previous instructions" and its many variants |
prompt_extraction | Attempts to make the model reveal its instructions or secrets |
role_hijack | Persona and mode switches such as unrestricted or developer modes |
authority_exploit | Fake system, developer, or admin markers and override codes |
social_engineering | Posing as the developer or owner, and research, testing, or fiction pretexts |
context_manipulation | Claims that earlier instructions were a test or that the real instructions are different, fake end-of-prompt markers, and references to a discussion that never happened |
output_control | Instructions that dictate the exact output, low risk on their own |
tool_hijacking | Commands that send out data or run shell code, such as posting environment variables or piping a download into a shell |
indirect_injection | Hidden-text markers and instructions addressed to an AI inside documents and tool results |
protocol_exploit | Fake MCP, tool, and extension messages, such as a claimed tool update |
encoding_attack | Instructions hidden in encodings, invisible characters, or Unicode tags |
classifier | The built-in classifier's verdict |
deny_phrase | Your denyPhrases |
How text is read
normalization controls what Shield undoes before matching: look-alike letters, invisible characters, spaced-out letters, leetspeak, typos, and decoding of hidden payloads (decodePayloads). See Normalization. false turns normalization off.
Adding your own detectors
detectAsync() accepts two hooks. secondaryDetector re-checks text Shield flagged, for example to clear false positives in your domain. escalate sends text Shield didn't flag to a detector you choose. With minScore: 0, it sends all unflagged text; a higher value sends only text the classifier was unsure about. Shield provides three detectors for this hook (see Slower detectors):
createModelDetector()runs a transformer classifier in your process. PointmodelorlocalPathat any Hugging Face text-classification model, including one you fine-tuned, and setlabel,threshold,maxTokens, andwindows.createLlmDetector()asks an LLM. Replace its instructions withpromptto describe what counts as an attack in your application.anyOf()combines several.
Any async function that returns a DetectResult or null works too.
Different rules for different sources
The provider wrappers take separate options for user messages (detect) and for tool results and documents (scanToolResults), so you can be stricter with content from outside:
shieldOpenAI(client, {
detect: { sensitivity: "balanced" },
scanToolResults: { sensitivity: "strict", denyPhrases: ["send the file to"] },
onDetection: "warn", // report instead of block while you tune
});onDetection: "warn" with onInjectionDetected lets you review what would be blocked before you enforce it. See Provider wrappers.
Output, tools, and agents
- Output scanning: choose the detectors (
secrets,pii,exfiltration,canary,injection), each with its own options, such as allowed domains for links and the PII types to find. - scanTools(): the description length limit and every detect option, plus pins for tool definitions.
- Tool policy: which tools may run, argument schemas, allow and deny lists, call limits, and which tools may send data out after untrusted input.
Local detect()
Prompt injection detection for user messages, documents, and tool results. Normalization, hidden-payload decoding, patterns, and a built-in classifier, in-process with no model download.
Local model detection
Run a configured transformer classifier in your process with local model artifacts.