SDKs & API
Guard API guide
Check, mask or block a prompt before your model call with POST /api/v1/guard.
Check a prompt before model execution
Call Guard once per model call, before you send anything to the AI provider. Full schema: API reference.
Request
{
"system_id": "cf84f936-95bc-45a4-bf98-9a1a16bf29c9",
"input": "Write a reply to Jana Novakova (jana.novakova@example.com) about her refund.",
"model": "gpt-4o-mini",
"user_id": "user-123",
"client_event_id": "0467f78f-5821-4827-a09b-d59a9b08866c",
"expected_languages": ["en"]
}system_iduuidrequiredThe AI system of the API key.
inputstring (max 64,000 chars)requiredThe text to check and mask, usually the latest user message.
prompt_contextstring (max 64,000 chars)Surrounding context such as earlier turns. Improves detection; not returned.
attachmentsarray (max 4)Files as text or base64. See Attachments and files.
client_event_iduuidCorrelation id for this model call. Reuse it as event_id on ingest.
user_idstringYour end-user identifier, shown in the activity log.
modelstringModel you are about to call.
expected_languagesstring[] (max 8)Language hints, for example en or cs.
origin"user_input" | "tool_output"Use tool_output for tool results fed back to the model.
pii_detection_mode"full" | "minimal"minimal is honoured only as one authorized retry of a slow full check.
metadataobjectFree-form telemetry stored with the event.
The request body is limited to 4 MiB. Unknown fields are rejected with 400 (invalid_payload).
Response
{
"allowed": true,
"detected_pii": true,
"transformed_input": "Write a reply to <PERSON_NAME_1> (<EMAIL_1>) about her refund.",
"input_char_count": 77,
"transformed_input_complete": true,
"client_deanonymization_enabled": false,
"guard_event_id": "9c1d1b8e-3f5a-4c8e-9a51-0f4f2e5c7d10",
"client_event_id": "0467f78f-5821-4827-a09b-d59a9b08866c",
"guard_latency_ms": 840
}Handling the verdict
const res = await fetch("https://app.getagentid.com/api/v1/guard", {
method: "POST",
headers: {
"x-agentid-api-key": process.env.AGENTID_API_KEY!,
"content-type": "application/json",
},
body: JSON.stringify({
system_id: process.env.AGENTID_SYSTEM_ID,
input: userMessage,
client_event_id: clientEventId,
}),
});
const verdict = await res.json();
if (!verdict.allowed) {
// Blocked by policy or fail-closed: do not call the model.
throw new Error(`Blocked by AgentID: ${verdict.reason}`);
}
// Always send the protected text, never the original.
const protectedInput =
typeof verdict.transformed_input === "string" ? verdict.transformed_input : userMessage;
const answer = await callModel(protectedInput);Rules:
- Read
allowedeven on HTTP200; a fail-closed system can answer200withallowed: false. - When
transformed_inputis present, send it instead ofinput; the same goes fortransformed_attachments. bypassed: truemeans the check was skipped in a fail-open system.transformed_inputis then missing; decide whether your application masks locally or continues.- In Shadow Mode (
shadow_mode: true) nothing is masked;simulated_decisiontells you what Active Guard would have done. - If
client_placeholder_mappingis present, use it only to restore the answer for the user, in memory.
Chat history
Protect the full message history that you send to the provider, not just the latest message. Guard returns a masked version of input and the attachments only; prompt_context helps detection but is not returned masked. So:
- keep earlier turns in the masked form you already sent (the
transformed_inputof their own Guard call), or - mask the assembled history locally with the SDK's
protectMessageHistory()before the provider call.
Call Guard once per model call, not once per historical message.
Tool results
When an agent feeds tool output back to the model, check it with origin: "tool_output". Guard then applies tool-output rules, for example blocking instructions injected into a tool result (tool_output_prompt_injection_blocked).
Blocking reasons
| Reason | Cause |
|---|---|
prompt_injection_blocked | Jailbreak or prompt override (SDK / API systems with Block Prompt Injection) |
tool_output_prompt_injection_blocked | Instructions injected into a tool result |
pii_blocked / secret_blocked | Personal information or a secret with blocking enabled |
toxicity_blocked | Toxic content with blocking enabled |
database_access_blocked / code_execution_blocked | Database access or code execution patterns with blocking enabled |
attachment_requires_secure_preprocessing | A file could not be read while blocking is enabled |
Policy violation: Term blocked by admin. | A content policy in Block mode |
Policy violation: Document blocked by admin. | A protected document |
system_suspended | API traffic of the system is paused |
Errors, limits and failure reasons are listed in Errors and rate limits.
Configuration endpoint
GET /api/v1/agent/config returns the effective guardrail flags of the key's system (Shadow Mode, failure mode, masking, restoration). The SDKs use it to decide local behaviour. See API reference.