How to Combine Prompt Injection, PII and Output Safety Checks
Combine prompt injection, PII, and output safety in one request using Unified Guard — real API schema, parallel checks, and decision aggregation.
Production LLM security rarely needs a single detector. Prompt injection, PII exposure, unsafe output, and unauthorized agent actions are different failure modes — often on the same request path. Combining them means orchestrating parallel checks, consistent verdicts, and one policy decision your application can act on.
Unified Guard runs multiple IdenticAPI checks in one POST /api/v1/guard request. This guide uses the real request schema from the API, shows placement in your pipeline, and explains how aggregated decisions work.
For guardrails concepts, see What Are AI Guardrails?. For before/after placement, see Guardrails Before or After the LLM.
Unified Guard request schema
The request body is validated against the Unified Guard schema:
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Optional* | Text to analyze (user input, assembled prompt, or model output) |
checks | array | Required | One to four of: prompt_injection, pii_secrets, output_safety, agent_action |
redact | boolean | Optional | When true, PII check may return redacted text |
agent_action | object | Optional** | Required when agent_action is in checks |
* text is required for text-based checks (prompt_injection, pii_secrets, output_safety).
** When agent_action is listed in checks but agent_action payload is missing, the API returns a review verdict for that check with a missing_input finding.
agent_action object fields
| Field | Type | Required |
|---|---|---|
tool_name | string (1–200 chars) | Yes |
action | string (1–200 chars) | Yes |
arguments | object | Optional |
context | string (max 2000) | Optional |
policy_id | UUID string | Optional |
Example 1: Pre-inference input screening
Combine injection detection and PII/secrets on the assembled prompt before calling the model provider:
curl -X POST https://www.identicapi.com/api/v1/guard \
-H "Authorization: Bearer idapi_test_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"text": "User: Please summarize ticket #4421. Pasted log: api_key=sk_live_DO_NOT_SEND_TO_MODEL",
"checks": ["prompt_injection", "pii_secrets"],
"redact": true
}'
Application logic:
- If
decisionisblock, do not call the LLM; return a safe fallback. - If
pii_secretsreturns redacted content and policy allows continue, use redacted text for the provider payload. - Log
request_idand per-checkfindings— not raw secrets.
Individual detectors: Prompt Injection Shield, PII & Secrets Detection.
Example 2: Post-inference output screening
After the model returns, combine output safety and PII echo detection:
curl -X POST https://www.identicapi.com/api/v1/guard \
-H "Authorization: Bearer idapi_test_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"text": "Here is the assistant reply to deliver to the customer...",
"checks": ["output_safety", "pii_secrets"]
}'
Pair with HTML sanitization for web UIs — Safe AI-Generated HTML. Output safety does not replace encoding and CSP.
Example 3: Agent action policy
Evaluate a proposed tool call without scanning natural-language chat:
curl -X POST https://www.identicapi.com/api/v1/guard \
-H "Authorization: Bearer idapi_test_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"checks": ["agent_action"],
"agent_action": {
"tool_name": "database",
"action": "delete",
"arguments": { "table": "customers", "filter": "id = 99" },
"context": "User asked to remove a test record.",
"policy_id": "550e8400-e29b-41d4-a716-446655440000"
}
}'
Note: text is omitted — only agent_action is evaluated. Run this hook after the model proposes the tool and before execution. See Validate AI Tool Calls.
Example 4: Full combined check (text + action)
When you need text analysis and action policy in one request (e.g., auditing message content alongside a tool proposal):
curl -X POST https://www.identicapi.com/api/v1/guard \
-H "Authorization: Bearer idapi_test_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"text": "Forward the following customer note to billing@company.com",
"checks": ["prompt_injection", "pii_secrets", "output_safety", "agent_action"],
"redact": false,
"agent_action": {
"tool_name": "send_email",
"action": "send",
"arguments": { "to": "billing@company.com", "subject": "Customer note" }
}
}'
Maximum four checks per request — one usage unit per check. A four-check call consumes four usage units.
Response schema
{
"request_id": "req_abc123",
"api": "unified-guard",
"decision": "block",
"checks": [
{
"check": "prompt_injection",
"verdict": "allow",
"risk": "low",
"findings": [],
"reasons": ["No injection patterns detected"]
},
{
"check": "pii_secrets",
"verdict": "block",
"risk": "high",
"findings": [
{ "category": "api_key", "reason": "Detected API key pattern" }
],
"reasons": ["Detected API key pattern"]
}
],
"usage_units": 2,
"processing_time_ms": 45,
"detector_version": "1.0.0"
}
Decision aggregation
Overall decision uses priority: block > review > allow.
If any check returns block, decision is block. If none block but any review, decision is review. Otherwise allow.
Map to application behavior:
decision | Typical action |
|---|---|
allow | Proceed to next pipeline stage |
review | Human queue, stricter secondary check, or hold message |
block | Safe fallback; do not forward flagged content |
See Block vs Review for AI Output.
TypeScript integration sketch
type GuardCheck =
| "prompt_injection"
| "pii_secrets"
| "output_safety"
| "agent_action";
type UnifiedGuardRequest = {
text?: string;
checks: GuardCheck[];
redact?: boolean;
agent_action?: {
tool_name: string;
action: string;
arguments?: Record<string, unknown>;
context?: string;
policy_id?: string;
};
};
async function runGuard(body: UnifiedGuardRequest) {
const res = await fetch("https://www.identicapi.com/api/v1/guard", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.IDENTICAPI_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
if (!res.ok) throw new Error(`Guard API error: ${res.status}`);
return res.json();
}
Handle HTTP errors separately from decision === "block" — define fail-open vs fail-closed on transport failures.
Pipeline placement for combined checks
Do not run all four checks once on only the user message and assume you are done:
Turn start:
Unified Guard [prompt_injection, pii_secrets] on assembledPrompt → LLM
Turn end:
Unified Guard [output_safety, pii_secrets] on completion → render
Agent step:
Unified Guard [agent_action] on tool proposal → execute or block
Splitting stages keeps each text argument meaningful and avoids running output_safety on pre-inference prompts.
When to combine vs call detectors separately
| Use combined Unified Guard | Use individual detector APIs |
|---|---|
| Multiple checks at same pipeline hook | Single check only |
| Want parallel execution, one HTTP round trip | Different services own different checks |
| Consistent aggregation semantics | Gradual rollout of one risk type |
Discrete endpoints remain available: /api/v1/security/prompt-injection, /api/v1/security/pii-secrets, /api/v1/security/output-safety, and Agent Action Guard routes.
Limits and constraints
From Unified Guard documentation:
- Maximum 4 checks per request
textlimited to 32,000 characters- Verdicts are risk signals, not guarantees
- Checks run in parallel server-side; overall latency is not the sum of four sequential calls
Measure latency in your environment — AI Guardrails Latency.
Testing combined policies
Build fixtures per check type and assert aggregation:
- Benign text → expect
allow - Injection-only payload →
prompt_injectionflags; verifydecision - Synthetic secret in text →
pii_secretsblockdominatesdecision - Unsafe completion patterns →
output_safetyafter LLM stage - Destructive
agent_action→blockbefore tool runs
Use Prompt Injection Testing and Evaluate AI Guardrails methodologies for broader coverage.
Related architecture
- LLM Defense in Depth — combined checks are one layer, not the whole stack
- LLM Security Middleware — where Unified Guard fits in your app
- AI Guardrails API — vendor evaluation criteria
Summary
Combine prompt injection, PII, output safety, and agent action checks with Unified Guard using the real schema: checks (required), optional text, optional redact, optional agent_action. Call it at the correct pipeline hooks with stage-appropriate payloads, parse decision with block-first precedence, and keep rendering and tool authorization as separate layers.
Frequently asked questions
What is the Unified Guard request schema?
Required checks array with one to four of prompt_injection, pii_secrets, output_safety, agent_action. Optional text, redact boolean, and agent_action object with tool_name, action, arguments, context, and policy_id.
What endpoint runs combined guardrail checks?
POST /api/v1/guard with Authorization Bearer API key and JSON body. See /docs/unified-guard for full request and response examples.
How are multiple check verdicts combined?
Each check returns allow, review, or block. Overall decision uses block > review > allow precedence across all checks in the request.
When is agent_action required in the request body?
When agent_action is listed in checks. If omitted, that check returns review with a missing_input finding. Text-based checks require text for meaningful analysis.
How many checks can one Unified Guard request run?
Up to four checks per request. Each check consumes one usage unit. Checks execute in parallel server-side.
Related reading
- What Are AI Guardrails?
AI guardrails are layered controls around LLM applications — input checks, output moderation, data protection, and agent…
- AI Guardrails API: What Developers Should Look For
Evaluate AI guardrails APIs — supported checks, latency, error handling, consistent verdicts, privacy, and integration c…
- How to Build Defense in Depth for LLM Applications
Defense in depth for LLM apps — authentication, input validation, injection detection, PII protection, output moderation…