Inferensys

Prompt

Unauthorized Action Detection Prompt for Agent Systems

A practical prompt playbook for agent platform engineers who need to detect and block agent actions that fall outside authorized permission sets before execution.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the ideal use case, required context, and limitations for the Unauthorized Action Detection Prompt.

This prompt is designed for agent platform engineers who need a reliable, pre-execution gate that inspects a planned agent action against a defined permission schema. Use it when your agent system generates tool calls, API requests, or function invocations that must be validated against a role-based or scope-based permission set before execution. The primary job-to-be-done is preventing an agent from exceeding its authorized boundaries, which is critical for systems operating on production infrastructure, sensitive data, or customer-facing services. The ideal user is an engineer embedding this check into an agent harness, tool-call middleware, or a permission enforcement proxy where a structured block-or-allow decision is required before any side effects occur.

This prompt assumes the agent's planned action is already parsed into a structured representation containing a tool name, arguments, and a target resource. It requires a defined permission schema as input, which maps roles or scopes to allowed actions and resource patterns. The prompt produces a deterministic JSON output with a block-or-allow decision, the specific violated boundary if blocked, and a safe alternative suggestion. Do not use this prompt for post-execution audit logging, user-facing authorization messages, or general content safety classification. It is not a replacement for a policy enforcement point (PEP) in a zero-trust architecture; rather, it is a semantic reasoning layer that can augment traditional policy engines when the permission boundary requires natural language understanding of the agent's intent.

Before implementing this prompt, ensure your agent harness can reliably extract the planned action into a structured format. If the action parsing is unreliable, the permission check will be brittle. Also consider the latency budget: this prompt adds a model inference call to the critical path of tool execution. For high-throughput systems, pair this with a caching layer for repeated permission checks or use a smaller, faster model for the classification task. Finally, always log the prompt's decisions for auditability, and implement a human-review queue for actions that fall into an ambiguous boundary where the model's confidence is low.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Unauthorized Action Detection Prompt works, where it fails, and what you must have in place before deploying it in an agent harness.

01

Good Fit: Pre-Execution Authorization Gate

Use when: The agent must evaluate a planned tool call or action against a defined permission schema before execution. The prompt acts as a policy enforcement point in the agent loop. Guardrail: Always run this check after the agent has selected a tool and generated arguments, but before the tool call is dispatched.

02

Bad Fit: Post-Hoc Audit Without Enforcement

Avoid when: You only need to log or review actions after they occur. This prompt is designed for blocking, not retrospective analysis. Guardrail: Use a separate audit classification prompt for log review. Do not repurpose a blocking prompt for passive observation, as its refusal language will confuse audit workflows.

03

Required Input: Machine-Readable Permission Schema

Risk: Without a structured permission schema (JSON list of allowed actions, resources, and constraints), the model cannot make consistent authorization decisions. Guardrail: Inject the agent's exact permission set as a structured [PERMISSION_SCHEMA] variable. Do not rely on natural language descriptions of what the agent 'should' be able to do.

04

Operational Risk: Latency in the Critical Path

Risk: Adding an LLM call before every tool execution doubles the latency of every agent action, which can break real-time or interactive use cases. Guardrail: Cache authorization decisions for repeated tool calls with identical arguments. For low-risk, high-frequency actions, use a deterministic rule engine instead of an LLM-based check.

05

Operational Risk: Model Drift in Authorization Logic

Risk: A model update can change how the prompt interprets the permission schema, leading to false blocks or false approvals without any prompt change. Guardrail: Pin the model version. Run a regression suite of known authorized and unauthorized tool calls against every new model release before deployment.

06

Bad Fit: Ambiguous or Context-Dependent Permissions

Avoid when: Authorization depends on dynamic context that cannot be fully expressed in a static schema (e.g., 'approve if the user seems trustworthy'). Guardrail: If the permission boundary requires subjective judgment, escalate to a human reviewer instead of relying on the prompt to make a nuanced trust decision.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt that detects unauthorized actions, blocks them, and suggests safe alternatives.

This prompt template is designed to be injected into your agent's pre-execution hook, right after a tool call is planned but before it is dispatched. Its job is to compare the agent's intended action against a predefined permission schema and return a structured block-or-allow decision. You must replace every square-bracket placeholder with your own permission taxonomy, agent role definition, and the specific action the agent is about to take. The prompt is self-contained so that it can be tested offline with historical tool-call logs before you wire it into a live harness.

text
You are a permission enforcement guard for an AI agent operating as [AGENT_ROLE]. Your only job is to compare a planned action against the agent's authorized permission schema and return a strict JSON decision.

## PERMISSION SCHEMA
[PERMISSION_SCHEMA]

## PLANNED ACTION
Action Name: [ACTION_NAME]
Action Arguments: [ACTION_ARGUMENTS]
Action Justification (provided by agent): [ACTION_JUSTIFICATION]

## INSTRUCTIONS
1. Determine whether the planned action is fully authorized, partially authorized, or completely unauthorized according to the permission schema.
2. If the action is unauthorized, identify the specific permission boundary that would be violated.
3. If a safe, authorized alternative exists, suggest it.
4. Never approve an action that falls outside the schema, even if the agent's justification sounds reasonable.

## OUTPUT SCHEMA
Return ONLY valid JSON with this exact structure:
{
  "decision": "allow" | "block",
  "violated_boundary": null | "string describing the specific permission boundary violated",
  "safe_alternative": null | "string describing a permitted alternative action",
  "confidence": 0.0-1.0
}

## CONSTRAINTS
- Do not explain your reasoning outside the JSON.
- If the action is allowed, violated_boundary and safe_alternative must be null.
- If the action is blocked, violated_boundary must be populated.
- Confidence must reflect how clearly the action maps to the schema.

To adapt this template, start by defining your permission schema as a structured list of allowed actions, their permitted argument ranges, and any conditional constraints (e.g., 'read-only on weekends' or 'max 100 records per call'). The schema can be a JSON object, a bulleted list, or a formal policy document—whatever your model can parse reliably. For high-risk deployments, add a second validation step after the model returns its JSON: check that the decision field is exactly allow or block, that violated_boundary is populated when block, and that confidence is a float between 0 and 1. If the JSON is malformed, retry once with the same prompt and a stronger format instruction. If it fails again, default to block and log the incident for human review. This prompt is a guardrail, not a policy engine—it should be paired with deterministic permission checks in your application code for defense in depth.

IMPLEMENTATION TABLE

Prompt Variables

Each placeholder required by the Unauthorized Action Detection Prompt. Wire these into your agent harness before invoking the model. Validation notes describe how to check the value at runtime to prevent injection, schema mismatch, or silent misclassification.

PlaceholderPurposeExampleValidation Notes

[AGENT_ROLE]

Defines the agent's operational identity and scope context for permission evaluation

customer-support-agent-v2

Must match an entry in the authorized role registry. Reject if value is not in the allowlist. Log mismatch for audit.

[PERMISSION_SCHEMA]

JSON schema describing allowed actions, resources, and constraints for the agent role

{"allowed_actions": ["read_ticket", "update_ticket"], "resources": ["tickets:*"], "max_retrieval_count": 50}

Validate as valid JSON against the PermissionSchema contract. Reject if schema is missing required fields or contains wildcard expansions not explicitly permitted.

[PLANNED_ACTION]

The action the agent intends to execute, including tool name and arguments

{"tool": "delete_user", "args": {"user_id": "U-9821"}}

Parse as JSON. Confirm tool name and args are present. Sanitize against injection patterns before passing to the classifier. Log the raw string for audit.

[ACTION_CONTEXT]

Optional context about why the agent selected this action, such as the preceding conversation or plan step

User requested account closure. Agent selected delete_user to fulfill the request.

Truncate to N characters to prevent prompt overflow. Null allowed if no context is available. Strip any embedded tool-call syntax that could confuse the model.

[OUTPUT_SCHEMA]

Expected JSON schema for the detection output to enforce structured parsing

{"type": "object", "properties": {"verdict": {"enum": ["allow", "block"]}, "violated_boundary": {"type": "string"}, "safe_alternative": {"type": "string"}}, "required": ["verdict"]}

Validate as valid JSON schema. Reject if schema does not include the required verdict field. Use this schema to validate the model's raw output before returning it to the orchestration layer.

[FALLBACK_BEHAVIOR]

Instruction for what the system should do if the model output is unparseable or confidence is below threshold

Block the action and escalate to the on-call security channel.

Must be one of the predefined fallback strategies: block, escalate, or log_and_allow. Reject unknown strategies. This value is injected directly into the prompt, so sanitize against prompt injection.

[CONFIDENCE_THRESHOLD]

Minimum confidence score required for an allow decision. Below this, the fallback behavior is triggered.

0.95

Must be a float between 0.0 and 1.0. Reject non-numeric strings. If the model returns a confidence score below this value, override the verdict with the fallback behavior. Log the override event.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Unauthorized Action Detection Prompt into an agent platform with tool-call interception, validation, and logging.

This prompt is not a standalone chat interaction; it is a guardrail component designed to be inserted into an agent's execution loop. The primary integration point is the tool-call interception layer. Before an agent's planned function call is dispatched to an external API, database, or local executor, the proposed action—including the function name, arguments, and the agent's stated reasoning—must be passed through this prompt. The prompt's output, a structured block decision, then acts as a gate: allow proceeds with execution, while block prevents the call and returns the safe_alternative to the agent's context for re-planning. This synchronous check prevents the primary failure mode of an agent silently exceeding its authority.

To implement this, you must maintain a permission schema that defines the agent's authorized scope. This schema, injected into the prompt's [PERMISSION_SCHEMA] placeholder, should be a machine-readable artifact (e.g., a JSON or YAML object) specifying allowed API endpoints, database tables, file paths, and read/write boundaries. The harness must parse the prompt's JSON output and validate it against a strict schema: { "decision": "allow" | "block", "violated_permission": "string | null", "safe_alternative": "string | null" }. If the model's output fails this structural validation, the harness should default to a fail-safe block and log the malformed response for immediate review. This design ensures that a model error never results in an unauthorized action.

For production hardening, wrap this prompt in a lightweight service with the following concerns: Logging every decision with the agent's planned action, the prompt's verdict, and the final outcome for auditability. Latency budgets are critical; this check adds a model round-trip to every tool call, so consider using a fast, cost-effective model for this classification task unless the permission boundaries are highly nuanced. Implement a retry policy with a maximum of one retry on a validation error, after which the action is blocked. Finally, establish a human review queue for blocked actions, especially those with a safe_alternative that the agent cannot autonomously execute, to prevent the agent from entering an infinite re-planning loop. The next step is to build a test harness that feeds this prompt a matrix of authorized and unauthorized tool calls to calibrate its boundary detection before deployment.

IMPLEMENTATION TABLE

Expected Output Contract

The JSON structure this prompt must return for every agent action evaluation. Use this contract to validate outputs before passing decisions to downstream enforcement logic.

Field or ElementType or FormatRequiredValidation Rule

decision

enum: allow | block | review

Must be exactly one of the three allowed values. Reject any other string.

violated_permission

string | null

Required when decision is block or review. Must match a permission key from the provided [PERMISSION_SCHEMA]. Null only when decision is allow.

safe_alternative

string | null

When decision is block, must contain a concrete alternative action within allowed scope. Must not be an empty string. Null allowed for allow and review decisions.

reasoning

string

Must be 1-3 sentences explaining which permission boundary was checked and why the decision was reached. Must reference the specific tool or action name from [PLANNED_ACTION].

confidence

number

Float between 0.0 and 1.0. Values below 0.7 should trigger a review decision or retry with additional context. Reject values outside this range.

boundary_category

string

Must match one of the categories defined in [BOUNDARY_TAXONOMY]. Common values: tool_access, data_scope, network_egress, file_system, user_impersonation, rate_limit.

evidence_citation

string

Must quote or reference the specific part of [PLANNED_ACTION] that triggered the violation. If decision is allow, cite the permission that authorizes the action. Must not be empty.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when detecting unauthorized actions in agent systems and how to guard against it.

01

Permission Schema Drift

What to watch: The agent's authorized permission set changes (new tools added, roles updated) but the detection prompt still references a stale schema. The model approves actions against outdated boundaries. Guardrail: Inject the permission schema dynamically from a single source of truth at runtime. Never hardcode permissions in the system prompt. Validate that the schema version matches the current deployment before every decision.

02

Tool Name vs. Intent Mismatch

What to watch: The agent plans an action using a tool name that sounds benign but maps to a privileged operation (e.g., run_query with admin credentials). The detection prompt approves it because the tool name doesn't signal risk. Guardrail: Map every tool to its required permission boundary in a structured manifest. The detection prompt must evaluate the tool's permission requirements, not just its name or description. Include a tool-permission mapping in the prompt context.

03

Argument Injection Bypass

What to watch: The agent requests an authorized tool but with arguments that escalate privilege (e.g., read_file with a path to a secrets directory). The detection prompt sees the tool as allowed and misses the argument-level violation. Guardrail: Validate tool arguments against parameter-level constraints. Include argument schemas with allowed ranges, paths, and resource identifiers in the detection context. Reject actions where arguments exceed the tool's authorized scope even if the tool itself is permitted.

04

Multi-Step Permission Escalation

What to watch: No single action violates a boundary, but a sequence of allowed actions chains together to achieve an unauthorized outcome (e.g., read a file, then send its contents to an external endpoint). The detection prompt evaluates each action in isolation and misses the compound risk. Guardrail: Maintain a short session-level action history. Include prior actions in the detection context so the prompt can evaluate whether the current action, combined with previous steps, crosses a boundary. Flag suspicious action chains even when individual steps appear safe.

05

Overly Permissive Safe Alternatives

What to watch: When the detection prompt blocks an action, it suggests a "safe alternative" that is itself dangerous or too broad (e.g., suggesting read_all_records instead of read_specific_record). The guardrail creates a new risk vector. Guardrail: Validate suggested alternatives against the same permission schema before returning them. Constrain alternative suggestions to the narrowest sufficient scope. If no safe alternative exists, the prompt should explicitly state that and escalate to human review rather than inventing a risky workaround.

06

False Negatives Under Adversarial Framing

What to watch: A user or upstream agent frames an unauthorized action as a hypothetical, a test, a debugging step, or an emergency override. The detection prompt accepts the framing and approves the action because the request sounds legitimate. Guardrail: Evaluate the concrete action and its effects, not the framing language. Include explicit instructions to ignore social engineering patterns (urgency, authority claims, hypothetical framing). Treat any action that touches a restricted boundary as requiring validation regardless of how it's described.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing the Unauthorized Action Detection Prompt before production deployment. Each row targets a specific failure mode or quality dimension that must pass before the prompt is considered ready for agent tool-call interception.

CriterionPass StandardFailure SignalTest Method

Exact Permission Match

Correctly blocks actions matching the [PERMISSION_SCHEMA] deny list with the exact permission name

Allows a denied action or returns an incorrect permission name in the violation field

Run 50 positive cases across all denied permissions; require 100% block rate and exact permission name match

Safe Alternative Quality

Returns a [SAFE_ALTERNATIVE] that is genuinely within allowed permissions and addresses the user intent when possible

Returns null for safe alternative when one exists, suggests another denied action, or returns an irrelevant action

Human review of 30 blocked outputs; 90% must have a useful, in-scope alternative

Allowed Action Pass-Through

Returns allowed=true with no blocking for any action explicitly listed in [PERMISSION_SCHEMA] allow list

False-positive block on an allowed action, or returns allowed=false with a fabricated violation

Run 50 positive cases across all allowed permissions; require 100% pass-through rate

Schema Adherence

Output strictly matches the [OUTPUT_SCHEMA] fields, types, and enum values

Missing required fields, extra fields, wrong types, or enum values outside the defined set

Schema validation check on 200 test runs; require 100% structural validity

Ambiguous Action Handling

Returns allowed=false with a clear explanation when the requested action is not explicitly covered by [PERMISSION_SCHEMA]

Guesses allowed=true for an unlisted action, or returns an empty violation reason

Test 20 actions not in the schema; require 100% block rate with non-empty violation reason

Tool-Call Format Robustness

Correctly interprets tool calls whether formatted as JSON, function-call syntax, or natural language action descriptions

Misses a denied action because the format differs from the few-shot examples

Test 10 denied actions in 3 formats each; require 100% detection rate across formats

Latency Budget Compliance

Completes classification in under 200ms for single-action checks to avoid blocking agent execution loops

Exceeds 500ms for simple checks, causing agent timeout or user-visible delay

Measure 100 invocations; 95th percentile must be under 200ms

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a static permission schema passed inline. Use a single model call before tool execution. Log decisions to stdout for manual review.

code
[PERMISSION_SCHEMA]
[AGENT_PLAN_OR_TOOL_CALL]

Watch for

  • Missing schema validation on the permission definition itself
  • Overly broad permission descriptions that let ambiguous actions through
  • No retry logic when the model returns malformed JSON
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.