Skip to content
AgentIDDocs

Type at least two characters to search titles, headings and content.

↑ ↓ to navigate↵ to open
AgentID Docs

SDKs & API

Guard API guide

Check, mask or block a prompt before your model call with POST /api/v1/guard.

POSThttps://app.getagentid.com/api/v1/guardReference

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_iduuidrequired

The AI system of the API key.

inputstring (max 64,000 chars)required

The 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_iduuid

Correlation id for this model call. Reuse it as event_id on ingest.

user_idstring

Your end-user identifier, shown in the activity log.

modelstring

Model 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.

metadataobject

Free-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

guarded-call.tsTypeScript
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:

  1. Read allowed even on HTTP 200; a fail-closed system can answer 200 with allowed: false.
  2. When transformed_input is present, send it instead of input; the same goes for transformed_attachments.
  3. bypassed: true means the check was skipped in a fail-open system. transformed_input is then missing; decide whether your application masks locally or continues.
  4. In Shadow Mode (shadow_mode: true) nothing is masked; simulated_decision tells you what Active Guard would have done.
  5. If client_placeholder_mapping is 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_input of 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

ReasonCause
prompt_injection_blockedJailbreak or prompt override (SDK / API systems with Block Prompt Injection)
tool_output_prompt_injection_blockedInstructions injected into a tool result
pii_blocked / secret_blockedPersonal information or a secret with blocking enabled
toxicity_blockedToxic content with blocking enabled
database_access_blocked / code_execution_blockedDatabase access or code execution patterns with blocking enabled
attachment_requires_secure_preprocessingA 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_suspendedAPI 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.