Skip to content

Keyword guardrail

The keyword guardrail is a Tier 1 (in-process, sub-millisecond) guardrail that scans request and response content for exact string matches. It is suited for topic filtering, brand protection, and blocking known-bad strings where pattern-based matching is not required.

Screenshot: Keyword guardrail editor in the Guardrail Builder Keyword guardrail editor

⚠️ Caution: A keyword guardrail with no keywords matches nothing — it is stored and listed, but the gateway returns pass for it on every request. An empty-string keyword is skipped at match time, so [""] counts as no keywords. GET /admin/v1/gateways/<ID>/detectors reports such a detector as active: false with inactive_reason: "no_keywords", and the Guardrail Builder badges it No keywords.

When to use the keyword guardrail

Use the keyword guardrail when you need fast, deterministic detection of specific, known strings. It adds no latency overhead and requires no external service. For detecting structured data formats such as email addresses or card numbers, use the Regex guardrail. For NLP-based PII detection, use the NLP PII Detector.

How it works

The guardrail performs plain string matching. Each keyword in the keywords array must appear verbatim in the inspected body. No wildcards, regular expressions, or stemming are applied.

  • Case-insensitive (default): "lawsuit" matches lawsuit, Lawsuit, LAWSUIT, and any other case variant.
  • Case-sensitive: "API" matches only API, not api or Api.
  • Whole-word matching (default false): When whole_word: true, "kill" matches only when surrounded by non-word characters — it does not match "skill" or "killing". The default is substring matching; enable whole_word: true for terms that should not match within longer words. A word character is a letter, combining mark or digit / number of any script (Unicode categories L, M, Nd, Nl, No — including superscript digits such as ²) (so Müller does not match inside Müllers, and Özdemir / Gauß match as whole words); everything else borders a word — spaces, line and tab breaks (a keyword at the start of a line matches), punctuation, quotes such as »…« and „…“, currency signs, symbols and emoji.
  • Case-insensitive matching folds ASCII and the accented Latin letters (Ö/ö, Ł/ł, …) — özdemir matches ÖZDEMIR.
  • Response phase — decoded text: a non-streamed JSON answer is read per JSON level, including the values inside a tool call's arguments (also when those arguments are not valid JSON but start like JSON — {", [", [{ or [[; text that merely begins with [1] or {x} is matched as text), as described under How escapes are read — so a provider that writes a character as an escape (M\u00fcller for Müller) is matched like any other answer, for block, flag and scrub alike. A scrub hit that cannot be masked in place — a keyword in any object key of the answer (top level or inside arguments) — blocks the answer instead. A value that is encoded several times is checked at every decoding level, and a value nested deeper than the gateway decodes (64 decoding steps) is refused for block, flag and scrub alike instead of being passed unchecked. Limit: a keyword split by invisible characters (a soft hyphen or a zero-width space inside the word) is not matched.
  • Special characters: a keyword may contain /, quotes or a backslash; it matches the text as written, with or without whole_word (since October 2026 — earlier, on the prompt and on tool results, a keyword holding /, " or \ never matched).
  • Tool results: with action: "scrub" or "block" the detector also runs on tool results returned to the model (web pages, files, knowledge, MCP) — see PII Protector — Which detectors cover tool results. How a JSON tool result is read, masked or withheld is described once under How escapes are read. A withheld result's location is recorded on the request log (where).

A single match from any keyword in the list is sufficient to trigger the configured block or flag action. Only the first matching keyword is surfaced — as the block reason on a block/flag action, or as first_kw on a scrub — not the full set of matches.

How escapes are read

Escapes are read the same way on the request, the response and tool results, for block, flag and scrub alike; the rules are described once under How escapes are read. For this detector:

  • Whole-word boundaries are judged on the decoded text.

Agent runs: what is scanned

On an agent run (invoke, Try it, draft preview, scheduled task, workflow copilot) the gateway builds the system message from the agent's instructions plus blocks it writes itself: the untrusted-data rule, the anti-fabrication rule, the destructive-operation safety note, the date line, and the prose of the structured-output directive. These platform blocks are neither the author's text nor user input. The keyword and regex guardrails do not scan them (since November 2026). Before, a block rule on a word one of them contained, such as CONFIDENTIAL, refused every agent run.

Part of the request keyword / regex prompt injection / jailbreak
The agent's instructions (and the organisation's system instruction) scanned not judged (trusted author text)
Platform blocks skipped skipped
User turns scanned scanned
Tool results and fetched pages scanned scanned

The gateway records each platform block as a span when it adds it to the system message. Nothing is matched on block text after the fact. Only exactly those bytes are left out, for block, flag and scrub alike, and only on the request phase. If anything does not line up, the whole request is scanned as before. That covers a system message changed after it was built, a span list that is not ascending and in range, and a system message that appears twice. A product test also makes sure no platform block contains a word from a shipped keyword preset: the Guardrail Builder's examples and config/guardrail-presets/.

Match location (where)

A request-phase block by a keyword or regex guardrail names where in the request it matched. It never names the matched term. The same location is recorded when a keyword or regex block inside the agent's own tool loop withholds one tool result or fails an agentic fetch (below).

where The match was in
system:instructions the system message: the agent's instructions, the organisation's system instruction, or the author's response schema
user a user turn
tool_result:<tool> the result of the tool <tool>. The name comes from the tool message itself or from the assistant tool call it answers.
fetched:<host> a fetched web page or document. Its gateway frame line [Untrusted web page: <url>] names the URL.

system:platform never appears, because platform blocks are not scanned.

The value is a closed format, checked on write, on the wire and on read: tool_result names match [A-Za-z0-9_.:-]{1,64} and hosts match [a-z0-9][a-z0-9.-]{0,252}. The tool name and URL come from the request, so they are untrusted. A name or host that does not fit is dropped, and the value becomes the bare tool_result or fetched. A malformed value is never passed through. The location is not authenticated. A tool name or fetched-page host in conversation history that a client sends is whatever the client wrote. Read it as a pointer for the author, not as proof of where the content came from. The field is absent when the location is unknown: a match in earlier model turns, in request metadata, or across two messages.

It is additive. error_class, the status and the block reason (the redacted keyword reference) are unchanged. It appears:

  • on the guardrail_blocked stream event as "where" (the chat notice and the agent's Try it, see Error codes);
  • on the request log as the protection marker guardrail_block_where (the gateway's Show recent activity table, column Where, and next to the detector on the Logs page; see Logs);
  • on the trace step guardrail_result as block_where.

A match that exists only in earlier conversation turns is masked and the request passes (earlier turns).

Inside the agent's own tool loop

A tool result inside the agent's own tool loop is checked by the tool-result pass, which withholds that one result instead of blocking (see Tool results above). The request goes on, so there is no guardrail_blocked event. Since November 2026 the pass records the location on the request log as guardrail_block_where:

What was withheld where
A tool result (MCP, files, knowledge, program output, …) tool_result:<tool>: the name of the tool call the result answers
A web page or document read with fetch_url fetched:<host>: the host of the fetched URL
A web-search result (native or tool) tool_result:web_search; fetched:<host> for a page the search read when the hit lies across that page's cut
An agentic fetch whose reader leg was blocked (the model gets Inner agent failed) fetched:<host>: the host of the URL it read. The reader's prompt is that page plus the question the agent asked about it, so the hit can also be in the question.

The same closed format and checks apply as above. A host or tool name that does not fit becomes the bare fetched or tool_result. Only the first such location of a request is kept: when several results are withheld in one run, the row names the first. If the request is then refused after all (for example by a response-phase block), the row shows only what that refusal recorded: a refusal without a location of its own drops the withheld result's location, so a Where never sits next to a block it does not belong to. Only keyword and regex blocks record it; a PII detector that withholds a result (a scan outage, a Presidio block) records none. The row appears in the gateway's Show recent activity table with the detector that withheld the result, and the Where column shows the location there too, as it does next to the detector on the Logs page. Its Outcome reads Blocked, because the detector acted (any detector type that withholds a result with a block, a Presidio block included; the request log records it as guardrail_withheld). The request itself was not refused, so the row is not marked as a refusal and its Reason reads withheld from the model; the request continued. On the Logs page the row carries the result withheld badge.

A web-search query a keyword rule refuses. When the model's own web-search query matches a keyword rule, no search is sent. The model is told the reason plainly ("matches a protected keyword or pattern of your organisation"), not that the PII scan was unavailable or that an injection guardrail fired. The keyword itself is not named.

Scrubbing matched keywords

With action: "scrub" the guardrail masks every matched keyword occurrence in place, replacing it with the scrub_placeholder value (default [REDACTED]), and records the outcome as scrubbed. On the request phase the masked body is what leaves Myra for the model; on the response phase the masked text is what is returned to the caller. The replacement is permanent — nothing restores the original value (see Verdicts); use the Custom PII Blacklist guardrail when the model's answer needs to reference the real values — it takes the same keyword list but tokenises reversibly, so the original is restored on the response leg. (The PII Protector is NER-based and has no keyword list, so it is not the substitute here.)

  • Every occurrence of every keyword is masked (not just the first), matching exactly the same case-sensitivity and whole-word rules the block/flag detection uses.
  • Matches that overlap or touch are merged into one placeholder wherever the text is read per JSON level (request messages and tool-call arguments, a JSON response and the values inside it, tool results written as JSON): ab and cd over abcd give one placeholder there. In text that is read only as written (a plain-text response, a request body that cannot be decoded) separate matches keep separate placeholders, even when they touch, and only overlapping matches merge. Matches that neither overlap nor touch always get their own placeholder.
  • Matching is always performed against the original text, so a keyword can never re-match inside a placeholder inserted for an earlier keyword.
  • An empty-string keyword is ignored (it never matches and never masks).

On the request phase block and flag read the same decoded content as the scrub: each JSON level is read decoded (see How escapes are read), and every string value that is itself a JSON document (a tool call's arguments, a tool result written as JSON) as a document of its own, at every decoding level (at most 64 decoding steps; deeper is refused rather than passed unchecked). A keyword hidden behind an escape such as \u00fc inside earlier tool-call arguments therefore triggers block and flag exactly as it triggers the scrub. On an earlier turn of the conversation, block masks the matching span with the placeholder instead of refusing the whole request; a match in the newest user message is refused. A match that lies wholly inside an occurrence of the detector's own placeholder is not a match (so an earlier turn the gateway already masked is not refused again), unless the placeholder itself consists only of a match of the detector (for example the keyword is secret and the placeholder is secret): then the placeholder is not exempt and a text holding it fires block and flag like any other match. The typography-normalised check for classified markings has no such exception: a placeholder that reads as the marking after normalisation still fires. A placeholder that contains a quote or a backslash is not recognised as the placeholder by block and flag, so its words count as a match there. A keyword detector for classified markings set to block keeps the exchange off (no earlier file edits are re-inserted).

Text the gateway's own protection controls write into a request is never a match for this detector: the placeholder that replaces a removed earlier turn ([earlier message removed by guardrail policy]), the text a keyword or regex scrub guardrail inserts (for example [REDACTED]), the <TYPE> masks the gateway writes for the entity types it knows (the NLP PII Detector; the mask of an unknown type is read as ordinary text), and the protection tokens that the PII Protector and the Custom PII detector issue. A conversation in which the gateway already masked or removed something is therefore not refused because the replacement text happens to contain one of your keywords. The same words anywhere else in the user's text still match: only an exact copy of the gateway's own text is treated as gateway text. Other texts the gateway adds to tool output, such as the notices that stand in for withheld tool results, files, documents and web-search queries, are checked like any tool output: in an earlier turn a match there is masked and the conversation continues, and in the newest turn it is refused. The exemption does not apply when a keyword matches the whole of that text (for example the keyword [redacted] against the placeholder [REDACTED], which it covers in full): that text is then not exempt, and a request in which the gateway had to remove an earlier turn is refused rather than passed. Tool-call arguments the gateway empties to {} when it removes an earlier turn are not exempt: a keyword that matches {} refuses such a request. The one exception to "never a match" is the classified-markings check (block_category classified_marking), which also looks at text the gateway wrote.

On the request phase the scrub also covers the conversation history the request carries — earlier messages, earlier tool results and the arguments of earlier tool calls included. Each JSON level is read decoded (see How escapes are read), and every string value that is itself a JSON document (a tool call's arguments, a tool result written as JSON) is decoded and matched as a document of its own, so a tool call's arguments stay valid JSON after masking. A match that runs from a field name into its value (for example password%W+%w+ over {"password":"…"}) masks the value; the field name and the JSON syntax around it stay as written. A keyword hidden behind an escape inside a value (for example \u00fc for ü) is found and masked as well. A match in a key or a number inside tool-call arguments, or one that covers only JSON syntax there, cannot be masked without changing the call, so the request is blocked instead. A match the gateway cannot mask in place — inside a document that is encoded as a string more than once, inside a document nested deeper than the gateway reads, or visible only after further decoding of a value (at most 64 decoding steps; deeper is refused rather than passed unchecked) — blocks the request (scrub_uncommittable) and the body is left unchanged. A match in a field name of the request itself is kept and recorded as "scrub not applied", also when other values were masked. When nothing could be masked the detector reports pass and the request is marked scrub_uncommittable. Text that already holds the scrub placeholder (an earlier turn the client sends again) is not masked a second time. A scrub whose placeholder consists only of a match of the detector cannot be applied: the request is blocked (scrub_uncommittable), and on the response phase the answer is withheld.

The refused value is not kept in the log. A request this scrub refuses (scrub_uncommittable, pii_in_number) is stored in the request log with its prompt masked by this detector's own rule (or, where that cannot be verified, the whole message withheld), never as sent; see the prompt column. A block or flag action keeps the prompt as sent.

💡 Note: Like the other body-rewriting maskers (NLP PII Detector, Regex scrub, PII Protector), keyword scrubbing is skipped on a wholly-local egress leg — when every candidate provider is first-party EU inference there is no third-party egress to protect against, so the model receives the user's own text unmodified. Scrubbing always applies on any leg that can reach an external provider.

💡 Note: For action: block, set whole_word: true and use unambiguous, specific terms. The default whole_word: false performs substring matching, which has high false-positive rates for short keywords — use action: flag for those, or enable whole_word: true.


Configuration reference

Field Type Default Description
type string — Must be "keyword"
name string — Human-readable label for this guardrail instance
action string "flag" What to do on a match: block, scrub, or flag
target string "request" Which traffic to inspect: request, response, or both
keywords array [] Exact strings to match. Empty-string entries are ignored.
case_sensitive boolean false When true, matching is case-exact; when false, matching is case-insensitive
whole_word boolean false When true, a keyword only matches when surrounded by non-word characters. Prevents "kill" from matching "skill". Default is substring matching. The Guardrail Builder sets true on a new keyword guardrail.
block_category string — Optional. "classified_marking" marks a classified-document-markings rule: it also matches typography-normalised text and forces attachments to be converted to text. See Classified-document markings.
scrub_placeholder string "[REDACTED]" Replacement text used when action is "scrub"

Example configurations

Block requests mentioning competitor names

{
  "type": "keyword",
  "name": "competitor-block",
  "action": "block",
  "target": "request",
  "keywords": ["AcmeCorp", "RivalAI", "OtherVendor"],
  "case_sensitive": false
}

Flag responses containing specific internal terms

Records a log entry whenever the model response contains an internal codename, without blocking or modifying the response.

{
  "type": "keyword",
  "name": "internal-term-flag",
  "action": "flag",
  "target": "response",
  "keywords": ["Project Nightingale", "Operation Keystone"],
  "case_sensitive": true
}

Scrub sensitive terms before the request leaves Myra

Masks the terms iban and user id with the placeholder wherever they appear in the request body, then forwards the masked request to the provider. The outcome is recorded as scrubbed.

{
  "type": "keyword",
  "name": "term-scrub",
  "action": "scrub",
  "target": "request",
  "keywords": ["iban", "user id"],
  "scrub_placeholder": "[REDACTED]"
}

Block prohibited topics

{
  "type": "keyword",
  "name": "prohibited-topics",
  "action": "block",
  "target": "both",
  "keywords": ["jailbreak", "ignore previous instructions", "DAN mode"],
  "case_sensitive": false
}

Detect jailbreak and prompt-injection attempts

The keyword guardrail catches the most common literal jailbreak and prompt-injection attempts with sub-millisecond latency and no sidecar dependency. The recommended action is flag rather than block because some phrases (e.g. "jailbreak" in a device support context) occur in legitimate contexts. Review flagged traffic before switching to block.

Set whole_word: false so inflected forms are also matched — for example "bypassing your restrictions" matches the phrase "bypass your restrictions".

{
  "type": "keyword",
  "name": "jailbreak-flag",
  "action": "flag",
  "target": "request",
  "case_sensitive": false,
  "whole_word": false,
  "keywords": [
    "ignore previous instructions",
    "ignore all instructions",
    "ignore your instructions",
    "disregard previous instructions",
    "disregard your instructions",
    "forget your instructions",
    "DAN mode",
    "do anything now",
    "jailbreak",
    "developer mode",
    "unrestricted mode",
    "your true self",
    "bypass your guidelines",
    "bypass your restrictions",
    "override your guidelines",
    "override your restrictions",
    "prompt injection",
    "[SYSTEM]"
  ]
}

The Guardrail Builder includes Block-safe example and Flag-only example preset buttons that populate a starter keyword configuration automatically.

⚠️ Caution: Keyword matching catches only literal, unmodified phrases. Motivated users can bypass it by rephrasing, inserting characters, switching language, or injecting prompts via retrieved documents. For coverage beyond literal phrases, combine this guardrail with Prompt Guard (Llama Guard 3), which performs semantic classification of request content. Llama Guard 3 runs locally within Myra's certified infrastructure — no prompt data leaves the Myra perimeter.


Configuring the keyword guardrail

Screenshot: Keyword guardrail card in the Guardrail Builder Keyword guardrail card — expanded view

Proceed as follows to configure the keyword guardrail in the Guardrail Builder:

  1. Open the gateway page (Organisation › AI setup › Gateways) and its Guardrails & residency tab with the Guardrails card.
  2. Click on the Keyword button.
    • A collapsed keyword guardrail card appears at the bottom of the list, with action flag, target request, and Whole-word matching switched on.
  3. Click on the card to expand it.
  4. Enter a name in the Name text field.
  5. Select the action from the Action drop-down list: block, scrub, or flag.
  6. Select the target from the Target drop-down list: request, response, or both.
  7. Type a keyword into the Keywords field and click on the Add button (pressing Enter also adds it). Each keyword appears as a removable chip; repeat for every keyword.
  8. Select the Case sensitive checkbox if exact case matching is required.
  9. Clear the Whole-word matching checkbox if substring matching is required (e.g. for product codes).
  10. When the action is scrub, the card shows a warning that the replacement is irreversible — nothing puts the original value back, in the answer or in the stored conversation — and points at the Custom PII Blacklist, which takes the same keyword list and tokenises reversibly.
  11. When the action is scrub, optionally set the Scrub placeholder — the text that replaces each matched keyword (default [REDACTED]).
  12. Click on the Save Guardrails button.

-> The keyword guardrail is saved and appears in the execution plan.


JSON number fields

The scan reads the request body exactly as the provider will receive it, including numeric fields (a card number sent as a JSON number, a timestamp, an ID, a seed):

  • Block mode sees the digits of a numeric field. Every number the gateway accepts is exact, and the scan sees its exact digits; a whole number whose magnitude is below 2^63 is written as plain digits, while an accepted number of magnitude 2^63 or more keeps exponent form (for example 1e+19) and its digits are not matched. A number the gateway cannot hold exactly (an integer literal a double cannot hold exactly such as 9007199254740993, or beyond 2^63, or more than 17 significant digits) is refused before the guardrails run (number_not_exact); see Numbers in the request body are forwarded exactly. With whole word on, a keyword still matches a number equal to it and the digits after a decimal point. This is a behaviour change for requests that carry sensitive values in numeric fields. The same scope as scrub applies: a keyword that is a digit sequence (with whole word off) also blocks inside an ID, a timestamp or the fraction digits of a float such as 0.30000000000000004.
  • Scrub (mask) mode never rewrites a number. When a keyword matches, wholly or partly, inside a JSON number (a keyword that is a digit sequence with whole word off, for example inside an ID or timestamp), the request is blocked with the reason pii_in_number instead of being masked. Matches inside text (strings) are masked as usual. Any digit run inside a JSON number counts, including the fraction digits of an ordinary float (a keyword 30000 matches {"temperature":0.30000000000000004}). Remedies: send the value as a string, round it client-side, or use a narrower keyword.

Pipeline position

The keyword guardrail is Tier 1 — it runs in-process with no external calls. All Tier 1 guardrails run before any Tier 2 guardrail. When multiple keyword guardrails are configured, they run in the order they appear in the guardrails array.

A block verdict from this guardrail stops the pipeline immediately. No subsequent guardrails run.


See also