New: AI Workspace – Secure AI for Organizations With Sensitive Data. Learn more.
Definition: AI guardrails (also known as LLM guardrails or AI guardrails) are technical validation rules for prompts, contextual data, and model responses.
Function: AI guardrails flag, mask, block, or log content based on policies.
Types: Key guardrails include input and output filters, PII protection, content moderation, prompt injection detection, and egress control.
Operation: Guardrails are most effective when implemented as a central pipeline within an AI gateway.
Limitations: Guardrails reduce risks but do not replace access controls, testing, monitoring, and human approvals.
AI guardrails function as a verification layer between users, applications, tools, and the AI model. They analyze inputs before the model is invoked, check outgoing tool or web requests, and monitor model responses before they are outputted. The rules typically run as a pipeline: quick pattern checks first, followed by more complex classifiers.
Guardrails are located in the data path between users or applications and the AI model. They are most effective when deployed in a central control layer, such as an AI gateway, where every request is subject to the same rules.
A check typically proceeds in the following steps:
Check the request: Before invoking the model, the guardrails analyze the prompt and, depending on the configuration, system instructions and attached content as well.
Apply result: Each rule returns a result. Depending on the outcome, processing is blocked, content is sanitized, violations are logged, or the request is allowed.
Invoke the model: Only an approved, and if necessary, sanitized request reaches the model.
Check Outbound Calls: If the model itself initiates an outbound call—such as a web request—an egress control checks the destination.
Check response: Output guardrails check the model’s response before it is delivered to users. Masked values can be reinserted here.
Logging: Which rule triggered and when is recorded in the log and serves as evidence for audits.
The order in which checks are performed affects costs and latency. It has proven effective to run fast, rule-based checks before more resource-intensive classifiers. If a simple pattern match already blocks a request, there’s no need for an NLP model to evaluate it further.
AI guardrails can be grouped according to their function. In practice, the types overlap: A keyword filter can serve as both an input filter and a policy rule. The key question here is at which point in the pipeline a risk arises if the rule is missing.
Input filter
Prompts, system instructions, attached content
Keywords, regular expressions, classifiers
Block, scrub, flag
Output filter
Model responses
Pattern matching, schema validation, classifiers
Block, flag, restore values
Content moderation
Harmful or Inappropriate Content
Security classifiers with categories
Block, flag
PII protection
Personally Identifiable Information (PII) and confidential data
Patterns, Named Entity Recognition (NER), tokenization
Scrub, tokenize, block
Topic and policy rules
Prohibited topics, terms, writing systems, formats
Keyword lists, writing system and code recognition
Block, flag
Prompt injection detection
Attempts to manipulate prompts and tool results
Phrase lists, trained classifiers
Block, flag
Egress control
Outgoing calls triggered by the model itself
Pattern matching, including encoded variants
Block, flag
Input filter
Prompts, system instructions, attached content
Output filter
Model responses
Content moderation
Harmful or Inappropriate Content
PII protection
Personally Identifiable Information (PII) and confidential data
Topic and policy rules
Prohibited topics, terms, writing systems, formats
Prompt injection detection
Attempts to manipulate prompts and tool results
Egress control
Outgoing calls triggered by the model itself
In short: The main types of AI guardrails are input and output filters, content moderation, PII protection, topic and policy rules, prompt injection detection, and egress control. They differ in what they check, how they detect it, and what action they trigger.
Input filters check everything that goes into a model. Output filters check everything that comes out. Both require their own rules: Inputs often contain sensitive data or attempts at manipulation, while outputs may contain unwanted content, incorrect formats, or unexpected source code.
Typical output checks include validating machine-processed responses against a JSON schema, detecting incomprehensible or erroneous text, and restoring previously masked values.
Content moderation detects harmful, illegal, or policy-violating content, such as violence, hate speech, or instructions for making weapons. This is achieved using safety classifiers that assign text to a range of categories. A widely used model is Meta’s Llama Guard 3, which distinguishes between 14 risk categories.
Content moderation can detect intent even when it is phrased indirectly. As a result, it is more prone to false positives, particularly in specialized contexts such as law, medicine, or IT security. Administrators should therefore specifically define which categories are active and whether a match should be blocked or merely flagged.
PII guardrails protect personally identifiable information (PII) such as names, email addresses, phone numbers, IBANs, or ID numbers. Three methods are commonly used:
Pattern-based detection for structured data with a fixed format, such as credit card numbers with a checksum or IBANs. It is fast and accurate but is not suitable for free-form text.
NLP-based detection via Named Entity Recognition for unstructured information such as names or locations in running text.
Reversible tokenization: Recognized values are replaced with placeholders before the model is called and reinserted in the response. The model works with pseudonymized data; users see the original values.
Topic and policy rules translate internal guidelines into technical checks. Examples include restricted project names or product codes, prohibited topics for a customer service bot, restrictions to specific writing systems, or a ban on exchanging source code via an AI endpoint.
These rules typically operate deterministically: a term is either on the list or it isn’t. This makes them transparent, but also easy to circumvent as soon as someone rephrases the query.
Prompt injection refers to inputs intended to cause a model to ignore its (security) specifications. In direct prompt injection, the instruction is contained within the prompt itself (“Ignore all previous instructions”). In indirect prompt injection, it is hidden within content that the model processes: in a retrieved webpage, an uploaded document, or a tool’s output.
Phrase lists intercept known attack patterns without measurable latency. Trained classifiers also detect rephrased, multilingual, or obfuscated variants. Because indirect attacks occur via tool results, guardrails should also check this content before it flows back into the model.
Egress control checks calls that a model initiates externally on its own, such as a web request or a search query. It takes effect when an indirect prompt injection has already succeeded and the model is intended to leak data via a malicious URL.
If the Guardrail detects structured identifiers or confidential information (such as email addresses, IBANs, or API keys) in the target, it blocks the request – but only if the value does not originate from the user’s own input. Normal web requests therefore continue to function. Egress control is thus the final safeguard against the leakage of structured data: It can take effect even if all upstream checks have overlooked an attack.
How guardrails are configured depends on the AI solution being used. The following examples show a typical configuration in the AI Gateway of Myra AI Workspace. There, guardrails are defined per gateway as a pipeline, either in the visual Guardrail Builder on the gateway’s details page or as JSON via the configuration API. AI guardrails consist of an ordered list of rules. Each rule specifies which detector checks whether a request, response, or both are being examined, and what action follows in the event of a match: block, mask, or flag.
Three parameters recur in every rule:
type: the detector (e.g., keyword, regex, jailbreak, or pii_protector)
target: the direction of the check (e.g., request, response, or both)
action: the response to a match (e.g., block, scrub, or flag). Not every detector supports every action.
Myra AI Workspace executes Guardrails in two tiers. Tier 1 runs directly in the gateway in the sub-millisecond range and includes regex, keyword, jailbreak detection, JSON schema, code detection, gibberish detection, language detection, and a proprietary PII blacklist. Tier 2 uses NLP models that run as sidecars within the Myra infrastructure and respond within milliseconds. These include NLP PII detection, PII Protector, Prompt Guard, and Prompt Injection. Tier 1 always runs before tier 2.
Other platforms use different terminology and detectors; however, the principle remains similar. The specific syntax also varies depending on the platform. What matters is that each rule defines a detector, a checking direction, and a response.
This pipeline blocks known jailbreak phrases, structured payment and access data, and then tokenizes personally identifiable information in the body text:
[
{
"type": "jailbreak",
"name": "block-jailbreaks",
"action": "block",
"target": "request"
},
{
"type": "regex",
"name": "block-payment-and-credentials",
"action": "block",
"target": "request",
"patterns": ["pci_pan", "credentials"]
},
{
"type": "pii_protector",
"name": "tokenize-pii",
"target": "both",
"entities": ["PERSON", "EMAIL_ADDRESS", "PHONE_NUMBER", "LOCATION"],
"fail_open": false
}
]
The pattern sets pci_pan (card and account data) and credentials (API keys, JSON Web Tokens) have a low false-positive rate and are therefore suitable for blocking. The PII Protector has no action: it always tokenizes. The setting fail_open: false ensures that requests are blocked rather than forwarded unprotected if the detection service is unreachable. If the model and all fallback models run on Myra infrastructure, masking is not required because the data does not leave the Myra infrastructure. Blocking rules and the masking of outgoing tool calls still apply.
A confidential project name should not appear in prompts:
{
"type": "keyword",
"name": "secret-project",
"action": "block",
"target": "request",
"keywords": ["Projekt Falke", "FALKE-2027"],
"case_sensitive": false,
"whole_word": true
}
The parameter whole_word: true ensures that only the complete keyword triggers a match. If a block occurs, the message specifies the detector that triggered it, but not the protected term itself. Thus, the error message does not reveal any confidential terms.
AI Guardrails cannot completely eliminate the risk of data leakage, but they can significantly reduce it. To achieve this, they should be arranged in multiple layers, tested with the organization’s own data, and regularly fine-tuned. This is because filtering is never 100% error-free. It may block legitimate requests (false positives) or sometimes overlook critical content (false negatives). Added to this are deliberate attempts to circumvent the system through rephrasing, encoding, or changing languages, as well as gaps in coverage.
In this context, a false positive means that Guardrail blocks a legitimate request. This frustrates users and, in the worst case, drives them back to “shadow AI”—that is, the unauthorized use of external AI services.
Proven countermeasures:
Mask rather than block error-prone patterns. A masked value disrupts work less than a rejected request.
Provide context: Providing usage context reduces the false positive rate for classifiers.
Use NLP instead of patterns for free-form text, because context reduces misinterpretations.
Rule-based guardrails only detect what is literally on the checklist. Rephrasing, translations, space and Unicode tricks, or invisible characters within a word are often enough to bypass a keyword or phrase filter. Classifiers detect significantly more variants, but they are also not foolproof.
There are also coverage limitations. Due to latency issues, classifiers often check only a subset of the data. Security teams should be aware of these limitations and take them into account during risk assessments.
NLP-based guardrails call upon a model. If the model is unavailable, the configuration must decide whether to allow or block the request. For data protection and prompt injection protection, the latter is the safer choice; for pure quality checks, the former may be acceptable. Each additional step also costs milliseconds. Therefore, fast rules should be placed at the beginning of the pipeline.
The counterpart to a false positive is a missed hit: a guardrail allows critical content to slip through. Only tests using real sample texts from your own organization will reveal how high both rates actually are. Even open-source tools openly acknowledge this limitation. The Presidio project, on which many PII detectors are based, points out that there is no guarantee that Presidio will detect all confidential information.
Another gap concerns the masking itself: If a model renders a masked value in its own words instead of repeating the placeholder, that value is not unmasked. The same applies to languages: Detection is calibrated for certain languages and works less reliably with others.
Guardrails do not replace either access control or processes. They are one security layer among many. These include access levels, restrictive permissions for tools and connectors based on the principle of least privilege, human approval steps, a clear separation of instructions and data in the Prompt system, as well as monitoring and auditing.
Myra AI Workspace, for example, flags content from files, web pages, and tool results as untrusted data by default so that the model does not follow any instructions embedded within them.
The appropriate combination depends on data classes, use cases, and regulatory requirements. Here’s a pragmatic example using Myra AI Workspace:
Personal data must not be used for the external model
PII tokenization or NLP-based PII detection with masking—mandatory for the project
Particularly sensitive data and trade secrets
Project set to “Local Only”; processing exclusively on models hosted by Myra on its own EU infrastructure
Block payment data and access credentials
Regex with exact-match patterns, "Block" action
Protect confidential terms
Keyword list (block) or PII blacklist (mask and restore)
Prevent jailbreaks and prompt injection
Jailbreak detector with predefined phrases, optional keyword detector with custom phrase list, plus the Llama Prompt Guard 2 classifier
Prevent data leakage via web requests
Egress control
Filter malicious content
Prompt Guard (Llama Guard 3) with individually activatable categories (S1 through S14)
Enforce structured output
JSON schema validation on the response
Prevent source code exchange
Code detection
Personal data must not be used for the external model
PII tokenization or NLP-based PII detection with masking—mandatory for the project
Particularly sensitive data and trade secrets
Project set to “Local Only”; processing exclusively on models hosted by Myra on its own EU infrastructure
Block payment data and access credentials
Regex with exact-match patterns, "Block" action
Protect confidential terms
Keyword list (block) or PII blacklist (mask and restore)
Prevent jailbreaks and prompt injection
Jailbreak detector with predefined phrases, optional keyword detector with custom phrase list, plus the Llama Prompt Guard 2 classifier
Prevent data leakage via web requests
Egress control
Filter malicious content
Prompt Guard (Llama Guard 3) with individually activatable categories (S1 through S14)
Enforce structured output
JSON schema validation on the response
Prevent source code exchange
Code detection
Start with a small, well-structured pipeline, test it with real sample texts, analyze the logs over several weeks, and expand the rules incrementally. Involve data protection and information security officers as well as business departments early on: Guardrails are technically implemented policies, and policies require responsible parties.
AI guardrails are automated validation rules that monitor requests to AI models and their responses. They detect, for example, personal data, prohibited topics, or attempts at manipulation, and flag, mask, or block the affected content. This allows organizations to technically enforce data protection and security policies regardless of the model used.

Björn Greif
Senior Editor
Björn started his career as an editor at the IT news portal ZDNet in 2006. 10 years and exactly 12,693 articles later, he joined the German start-up Cliqz to campaign for more privacy and data protection on the web. It was then only a small step from data protection to IT security: Björn has been writing about the latest trends and developments in the world of cybersecurity at Myra since 2020.