Agent runtime security
Extend the existing privacy policy to inspect sensitive data across agent boundaries, and configure prompt injection protection separately.
Why Use Runtime Security
An authorized user may read customer records while still being prohibited from sending them to another destination. Retrieved documents and tool responses may also contain instructions that redirect an agent.
Runtime security uses independent classifiers and application-enforced actions. Configure sensitive data through the existing pii option, and prompt injection through security.promptInjection. Access controls and guardrails continue to apply.
Quick Start
Use an existing text agent and an administrative backend connection. See securing AI agents for access requirements. Your deployment must serve the default detector models, or you must select available overrides.
- TypeScript
- Python
await this.squid
.ai()
.agent('support-agent')
.updatePii({
onDetect: 'redact',
scopes: ['context', 'output', 'toolArguments'],
entities: ['email', 'ssn', 'creditCard', 'secret'],
});
await this.squid
.ai()
.agent('support-agent')
.updateSecurity({
promptInjection: { onDetect: 'block' },
});
await self.squid.ai().agent('support-agent').update_pii({
'onDetect': 'redact',
'scopes': ['context', 'output', 'toolArguments'],
'entities': ['email', 'ssn', 'creditCard', 'secret'],
})
await self.squid.ai().agent('support-agent').update_security({
'promptInjection': {'onDetect': 'block'},
})
updatePii / update_pii merges with the existing privacy settings. Arrays replace the previous array. Set onDetect to off to disable privacy inspection. Scopes default to ['input'], so select output explicitly to inspect responses.
updateSecurity / update_security replaces the security object. Pass {} to disable prompt injection protection. Privacy settings live in pii and are preserved when you update injection settings.
Configuration
Existing settings and compatibility
Existing pii: { onDetect: 'reject' } configurations retain their input-only behavior, six default PII categories, classifier selection and PII_DETECTED_IN_PROMPT / PII_SCREENING_UNAVAILABLE errors. Adding explicit scopes, a runtime timeout or effort, the secret category, or selecting monitor / redact enables runtime inspection.
Legacy input rejection runs before runtime redaction. Security classifiers inspect the original text; privacy inspection does not rewrite another classifier's input. Existing guardrails.disablePii remains an instruction to the answering model and can be used alongside independent inspection.
Detector models and defaults
| Policy | Model override | Runtime default role |
|---|---|---|
| Privacy | pii.classifierModel | chat.pii |
| Prompt injection | security.promptInjection.model | chat.promptInjection |
Omit the override to use the default model. Set pii.classifierModel to null to clear a saved override; an omitted field in updatePii preserves the existing value. Omitting the injection model from replacement settings clears its override.
Both runtime roles initially use gpt-6-luna when a credentialed platform OpenAI connection serves it. Existing assignments and explicitly cleared roles are preserved. Squid operates platform assignments on Squid Cloud; self-hosted deployment operators configure their own connections and roles. Application authors can select available per-agent overrides.
Legacy input-only rejection continues to use its existing chat.classifier selection behavior. Runtime inspection fails closed when its selected model or default role is unavailable; it does not substitute the answering model.
The following example assumes your deployment serves gpt-6-luna and gpt-6.1-terra.
- TypeScript
- Python
await this.squid
.ai()
.agent('support-agent')
.upsert({
options: {
model: 'gpt-6.1-terra',
guardrails: { disablePii: true, professionalTone: true },
pii: {
onDetect: 'reject',
classifierModel: 'gpt-6-luna', // Omit to use the default model
reasoningEffort: 'low',
timeoutMs: 30000,
scopes: ['input', 'context', 'output', 'toolArguments'],
entities: ['email', 'ssn', 'secret'],
customRules: ['Internal case numbers such as CASE-12345'],
allowList: ['support@example.com'],
},
security: {
promptInjection: {
onDetect: 'block',
model: 'gpt-6-luna', // Omit to use the default model
scopes: ['input', 'context'],
timeoutMs: 30000,
},
},
},
});
await self.squid.ai().agent('support-agent').upsert(options={
'model': 'gpt-6.1-terra',
'guardrails': {'disablePii': True, 'professionalTone': True},
'pii': {
'onDetect': 'reject',
'classifierModel': 'gpt-6-luna', # Omit to use the default model
'reasoningEffort': 'low',
'timeoutMs': 30000,
'scopes': ['input', 'context', 'output', 'toolArguments'],
'entities': ['email', 'ssn', 'secret'],
'customRules': ['Internal case numbers such as CASE-12345'],
'allowList': ['support@example.com'],
},
'security': {
'promptInjection': {
'onDetect': 'block',
'model': 'gpt-6-luna', # Omit to use the default model
'scopes': ['input', 'context'],
'timeoutMs': 30000,
},
},
})
Privacy fields
| Field | Meaning |
|---|---|
onDetect | off, reject, monitor, or redact. monitor records a detection and warns without blocking. |
classifierModel | Optional model override. null restores the default model. |
scopes | Nonempty selection of input, context, output, toolArguments. Default: input. |
entities | email, phoneNumber, creditCard, ssn, iban, passport, secret. Default: the six PII categories. |
customRules | Additional sensitive-data criteria, one description per entry. Empty categories use these rules alone. |
allowList | Exact approved values excluded from matches. |
reasoningEffort | Optional classifier effort. Omitted, uses the model's default. |
timeoutMs | Runtime inspection timeout, 1000 to 300000 milliseconds. Default: 60000. |
Prompt injection accepts onDetect: 'off' | 'monitor' | 'block', model, reasoningEffort, timeoutMs, customRules, and scopes: ['input', 'context'] (the default).
Advanced policies support at most 100 rules and 100 approved values, each at most 2000 characters. Each inspection is limited to 100000 characters; oversized text is withheld. CLI classifier models are unsupported. Existing legacy policies retain their accepted configuration behavior.
The size limit applies to the complete serialized value being inspected. Context inspection includes the combined conversation history and retrieved chunks, so a conversation can reach this limit before the answering model's context window is full. Oversized tool and database/API results are also refused. If a conversation reaches the limit, trim or clear its history, or start with a new memoryId; retrying the same history continues to fail with SECURITY_INPUT_TOO_LARGE.
Core Concepts
Protection boundaries
- Input: User prompts and caller-supplied instruction content, before routing and answering.
- Context: Retrieved text, conversation content, tool descriptions/results/errors, and built-in query subagents. Stored system instructions are inspected for sensitive data without treating the owner's instructions as an injection.
- Output: Response text, annotations, validation results, and routing results before release.
- Tool arguments: Arguments before a Squid-controlled operation executes.
rejectandredactboth block sensitive tool arguments because rewriting them could change the operation.
Redaction replaces exact detected values with [REDACTED]. It never accepts a model-authored replacement object. Unsafe structural or control-identifier changes cause refusal.
Selecting output inspection buffers the response until screening completes. Protected conversation memory retains the user message and inspected final answer. Blocked input adds no turn; failed privacy-protected turns do not persist unchecked answers.
Coverage and auditing
Policies are stored on the agent. Callers cannot disable them through request options. Delegated agents inherit their parent's runtime policies.
Decision events identify the detector, scope and action without matched values. Advanced privacy inspection withholds free-text agent audit and progress payloads. Existing stored logs are not rewritten.
Runtime policies inspect text. Attachments, generated files, native web grounding, CLI models and direct realtime voice are unsupported while runtime protection is active. Existing legacy input-only PII rejection retains its feature compatibility. Detectors receive the text they inspect, so choose an appropriate provider and deployment.
Built-in database/API queries remain inside protected Core execution. Their separate query memory and raw-result exports are disabled. Spreadsheet analysis and Python execution are unsupported under runtime protection. Custom backend code remains trusted: Squid inspects arguments and results, but cannot police arbitrary external calls or storage inside custom code.
Classifiers can miss detections or flag legitimate content. Access controls, tool permissions and destination restrictions remain necessary.
Agent Studio
Open the agent's Settings, then Agent Guardrails. Privacy and prompt injection contains the full sensitive-information policy and separate injection controls. Choose the action, model, scopes, timeout, categories and rules. Use default model clears a model override. Editing injection settings preserves an existing legacy privacy policy.
The PII response instructions guardrail asks the answering model to avoid PII. It remains separate from the classifier-enforced privacy policy.
REST API
Set SQUID_APP_URL to your application origin: https://YOUR_APP_ID.APP_REGION.squid.cloud for production, https://YOUR_APP_ID-dev.APP_REGION.squid.cloud for deployed development, or https://YOUR_APP_ID-dev-YOUR_SQUID_DEVELOPER_ID.APP_REGION.squid.cloud for local backend development. Set SQUID_API_KEY to the application API key for that environment and keep it in backend code. See OpenAPI base URLs.
updatePii merges privacy settings:
curl --fail-with-body --request POST \
"${SQUID_APP_URL}/openapi/squid-api/v1/ai/agent/updatePii" \
--header "Content-Type: application/json" \
--header "Authorization: ApiKey ${SQUID_API_KEY}" \
--data '{"agentId":"support-agent","pii":{"onDetect":"redact","scopes":["output"],"entities":["email","secret"]}}'
updateSecurity replaces prompt injection settings:
curl --fail-with-body --request POST \
"${SQUID_APP_URL}/openapi/squid-api/v1/ai/agent/updateSecurity" \
--header "Content-Type: application/json" \
--header "Authorization: ApiKey ${SQUID_API_KEY}" \
--data '{"agentId":"support-agent","security":{"promptInjection":{"onDetect":"block"}}}'
Error Handling
| Error prefix | Meaning |
|---|---|
PII_DETECTED_IN_PROMPT / PII_SCREENING_UNAVAILABLE | Legacy input rejection or unavailable legacy screening. |
PROMPT_INJECTION_DETECTED | A blocking injection policy detected an override. |
SENSITIVE_DATA_DETECTED | Runtime privacy rejected sensitive content or tool arguments. |
SECURITY_SCREENING_UNAVAILABLE | Runtime classification failed, timed out or returned an invalid result. |
SECURITY_CLASSIFIER_UNSUPPORTED_CLI_MODEL | A runtime classifier is a CLI model. |
SECURITY_INPUT_TOO_LARGE | Text exceeded the inspection limit. |
SECURITY_REDACTION_FAILED | Safe structural redaction was not possible. |
AGENT_SECURITY_TURN_FAILED | An unclassified failure was withheld to avoid exposing unchecked error text. |
AGENT_QUOTA_EXCEEDED, AGENT_RATE_LIMITED, AGENT_UPSTREAM_RATE_LIMITED | A quota or rate limit was reached. Public ask endpoints return HTTP 429. |
AGENT_UPSTREAM_UNAVAILABLE | The model provider is temporarily unavailable. Public asks return HTTP 503. |
AGENT_UPSTREAM_TIMEOUT | The model request timed out. Public asks return HTTP 504. |
AGENT_SECURITY_UNSUPPORTED_* | A feature falls outside supported runtime boundaries. |
INVALID_AGENT_SECURITY_* | Configuration passed to an update method or stored on the agent is invalid. |
HTTP or job details can precede the code. Check for the code within the exception message. Never retry with privacy or injection protection disabled.
- TypeScript
- Python
try {
const answer = await this.squid.ai().agent('support-agent').ask('Summarize the customer case.');
console.log(answer);
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
if (message.includes('PROMPT_INJECTION_DETECTED')) {
console.log('The request was blocked by the prompt injection policy.');
} else if (message.includes('SENSITIVE_DATA_DETECTED') || message.includes('PII_DETECTED_IN_PROMPT')) {
console.log('The request was blocked by the privacy policy.');
} else if (message.includes('SECURITY_SCREENING_UNAVAILABLE') || message.includes('PII_SCREENING_UNAVAILABLE')) {
console.log('Screening is unavailable. Try again later with the same policy.');
} else {
throw error;
}
}
from squidcloud import SquidHttpError
try:
answer = await self.squid.ai().agent('support-agent').ask('Summarize the customer case.')
print(answer)
except SquidHttpError as error:
message = str(error)
if 'PROMPT_INJECTION_DETECTED' in message:
print('The request was blocked by the prompt injection policy.')
elif 'SENSITIVE_DATA_DETECTED' in message or 'PII_DETECTED_IN_PROMPT' in message:
print('The request was blocked by the privacy policy.')
elif 'SECURITY_SCREENING_UNAVAILABLE' in message or 'PII_SCREENING_UNAVAILABLE' in message:
print('Screening is unavailable. Try again later with the same policy.')
else:
raise
Best Practices
- Test legitimate traffic and adversarial cases before enabling rejection broadly.
- Use
monitorto measure detections; it allows matched content to continue. - Select the necessary scopes and categories, and approve shared public values explicitly.
- Centrally manage defaults and choose per-agent overrides when necessary.
- Evaluate latency, spend, false positives and missed detections after policy/model changes.