This prompt is designed for cloud engineers and SRE teams who encounter an 'Access Denied' error during automated pipeline execution or manual operations in AWS, GCP, or Azure. The core job-to-be-done is rapid, safe recovery: you provide the specific denied API call and the existing IAM policy document, and the model generates a minimal, least-privilege policy addition that resolves the immediate permission boundary. This is a surgical recovery tool, not a policy authoring workshop. It assumes you already have a functional policy that is simply missing one or more specific actions for a resource.
Prompt
Cloud IAM Permission Denied Recovery Prompt

When to Use This Prompt
Defines the precise operational scenario for the Cloud IAM Permission Denied Recovery Prompt, its ideal user, required inputs, and critical limitations.
To use this prompt effectively, you must have two concrete pieces of context ready: the exact API action that was denied (e.g., s3:GetObject, storage.objects.get) and the complete, current JSON policy document attached to the failing identity. Without the current policy, the model cannot calculate the minimal diff and may suggest overly broad permissions. This prompt is ideal for fast recovery in CI/CD pipelines where a new feature requires a previously ungranted permission, or for operators debugging a sudden permission failure in a previously working service. The output is a corrected policy statement, not a full policy document, which you must then validate and apply through your standard IaC or manual change process.
Do not use this prompt for generating IAM policies from scratch, as it requires an existing policy to diff against. It is also unsuitable for cross-account role assumption failures where the root cause is a misconfigured trust policy on the target role, not a permissions policy on the calling identity. Finally, avoid this prompt for complex multi-service authorization failures where the denial is caused by an implicit deny from a Service Control Policy (SCP), permissions boundary, or session policy; the prompt's scope is limited to identity-based policy statements. In all cases, a human must review the generated policy addition for least-privilege compliance and resource scope correctness before applying it to any environment.
Use Case Fit
Where the Cloud IAM Permission Denied Recovery Prompt works well, where it fails, and the operational risks to manage before putting it into a production harness.
Good Fit: Single-Action Denials
Use when: the error message clearly identifies one denied API action and the current policy document is available. The prompt excels at mapping a specific denial to the minimal required permission. Guardrail: validate that the input error is a permission-denied type, not a throttling or quota error, before invoking the prompt.
Bad Fit: Multi-Service Orchestration
Avoid when: the failure spans multiple services, involves implicit permissions from service-linked roles, or requires cross-account access analysis. The prompt lacks the context to reason about transitive dependencies. Guardrail: route complex access failures to a human operator or a multi-step agent that can map the full resource graph before suggesting policy changes.
Required Inputs
Must provide: the exact denied API call (service:action format), the full current IAM policy document as JSON, and the resource ARN. Guardrail: reject incomplete inputs at the harness level. If the error message is truncated or the policy is redacted, return a structured input-request prompt instead of guessing.
Operational Risk: Over-Permissioning
Risk: the model may suggest a wildcard action or resource when a scoped permission would suffice, violating least-privilege. Guardrail: post-process every suggested permission addition through a policy validator that checks for wildcards and flags any action broader than the denied call. Require human approval before applying.
Operational Risk: Syntax Drift
Risk: cloud providers update IAM action names, condition keys, and resource formats. A prompt trained on stale knowledge may suggest deprecated or invalid permissions. Guardrail: validate every suggested permission against the live provider's IAM reference. If the action is unrecognized, fall back to a human review queue with the original error context.
Operational Risk: Condition Blindness
Risk: the denial may be caused by a missing or incorrect IAM condition, not a missing action. The prompt may add a broad permission when a condition scoped to a VPC, tag, or time range is the correct fix. Guardrail: include a pre-check that inspects the existing policy for condition blocks. If conditions are present, prompt the model to explain why the denial occurred before suggesting an action addition.
Copy-Ready Prompt Template
A reusable prompt that reads a denied API call and current IAM policy to suggest a minimal, least-privilege permission addition.
The prompt below is designed to be dropped into a recovery harness when a cloud API call returns an access-denied error. It expects the raw error message, the denied API action, and the current IAM policy document attached to the principal that was denied. The model's job is to produce a corrected policy statement that grants only the missing permission, not to rewrite the entire policy or suggest broad wildcard permissions. Replace every square-bracket placeholder with live data before sending the prompt to the model. If any placeholder is empty, the harness should abort the retry and escalate to a human operator rather than sending an underspecified prompt.
textYou are an IAM policy repair assistant operating under a strict least-privilege constraint. ## INPUT - Denied API Call: [DENIED_API_ACTION] - Error Message: [ERROR_MESSAGE] - Current IAM Policy Document (JSON): [CURRENT_POLICY_JSON] - Cloud Provider: [CLOUD_PROVIDER] - Resource ARN (if available): [RESOURCE_ARN] ## CONSTRAINTS 1. Propose the smallest possible permission addition that resolves the denial. 2. Never suggest wildcard actions (e.g., `*:*` or `*`) unless the current policy already grants an equivalent wildcard and you are matching its scope. 3. Never suggest wildcard resources unless the error and current policy clearly indicate a resource-level wildcard is already in use. 4. If the denial is caused by a condition key mismatch rather than a missing action, explain the condition conflict instead of adding new actions. 5. If the current policy already contains the required permission but a condition, boundary, or SCP is blocking it, state that explicitly and do not suggest policy changes. 6. Output only the minimal new policy statement in the provider's native JSON policy format, plus a one-sentence explanation of what was added and why. ## OUTPUT_SCHEMA Return a JSON object with exactly these fields: { "action": "add_statement" | "modify_condition" | "no_change" | "escalate", "explanation": "One-sentence explanation of the diagnosis and change.", "new_statement": { ... } | null, "condition_note": "string explaining condition conflict, if applicable" | null } ## EXAMPLES Example 1 - Missing action: Input: Denied API Call: s3:GetObject, Error: AccessDenied, Current Policy: {"Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":"arn:aws:s3:::my-bucket"}]} Output: {"action":"add_statement","explanation":"Added s3:GetObject permission on the bucket objects to resolve the GetObject denial while preserving the existing ListBucket permission.","new_statement":{"Effect":"Allow","Action":["s3:GetObject"],"Resource":"arn:aws:s3:::my-bucket/*"},"condition_note":null} Example 2 - Condition mismatch: Input: Denied API Call: ec2:StartInstances, Error: AccessDenied due to condition key, Current Policy includes a condition restricting ec2:StartInstances to tag Environment=prod but the instance has Environment=staging. Output: {"action":"modify_condition","explanation":"The policy allows StartInstances only when the Environment tag equals prod, but the target instance is tagged staging. No new action is needed; the condition must be updated or the instance tag changed.","new_statement":null,"condition_note":"Condition key ec2:ResourceTag/Environment requires value 'prod'; target instance has 'staging'."} ## RISK_LEVEL [RISK_LEVEL] If RISK_LEVEL is "high" or "critical", append: "Flag this output for human review before applying. Do not auto-apply the suggested policy change."
After copying the template, wire it into a recovery harness that validates the model's output against the provider's IAM policy schema before any apply step. If the action field is escalate, the harness must route the case to a human operator with the full error context and model explanation. If the action is add_statement, diff the proposed statement against the current policy to confirm it adds only net-new permissions and does not widen existing ones. For AWS, validate the statement against the IAM policy grammar using a library like policyuniverse or iam-floyd before calling PutRolePolicy or equivalent. For GCP, validate against the allowable permissions list for the target resource type. For Azure, validate against the provider's resource provider operations list. If validation fails, increment the retry counter and re-prompt with the validation error included in [ERROR_MESSAGE]. After three failed validation attempts, escalate to a human and log the full retry trace.
Do not use this prompt for denials caused by organization-level SCPs, service control policies, or identity boundary policies that the principal's direct policy cannot override. In those cases, the model should return action: escalate with an explanation that the block is external to the submitted policy document. Also avoid using this prompt when the denial involves cross-account access or resource-based policies on the target resource, unless those policies are included in [CURRENT_POLICY_JSON] as additional context. The prompt is scoped to identity-based policy repair only.
Prompt Variables
Required inputs for the Cloud IAM Permission Denied Recovery Prompt. Validate each placeholder before sending to prevent policy-syntax errors and hallucinated ARNs.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[DENIED_API_CALL] | The exact API action that was denied, including service prefix | s3:PutObject | Must match the format <service>:<action>. Parse from cloud audit log or error message. Reject if empty or missing colon delimiter. |
[RESOURCE_ARN] | The full ARN of the resource the principal attempted to access | arn:aws:s3:::my-bucket/* | Validate ARN format with regex for the target cloud provider. Must include service, region, account, and resource segments. Null allowed if the denial is service-level rather than resource-level. |
[CURRENT_POLICY_DOCUMENT] | The existing IAM policy JSON attached to the principal that received the denial | {"Version":"2012-10-17","Statement":[...]} | Must be valid JSON parseable by the harness before prompt assembly. Reject if the Statement array is missing or the Version field is absent. Do not send truncated policies. |
[PRINCIPAL_TYPE] | The identity type making the request: User, Role, or Group | Role | Must be one of the enumerated set: User, Role, Group. Derive from the policy attachment context. Reject unknown values to prevent incorrect policy binding suggestions. |
[CLOUD_PROVIDER] | The target cloud platform for policy syntax and service prefix rules | AWS | Must be one of: AWS, GCP, Azure. Controls which permission grammar and resource hierarchy the prompt enforces. Reject unrecognized providers. |
[LEAST_PRIVILEGE_SCOPE] | Boundary constraints for the suggested permission, such as specific actions or resource conditions | Limit to s3:GetObject and s3:ListBucket only | Free-text but must be non-empty. If the operator provides no scope, default to 'Suggest only the minimal action required to resolve the denial.' Validate that the scope does not request wildcard admin actions. |
[ERROR_CONTEXT] | Additional error metadata such as condition keys, explicit denies, or SCP references from the denial message | Explicit deny from SCP: DenyAllS3OutsideRegion | Optional. If provided, must be a non-empty string extracted from the cloud audit log. Null allowed. When present, the prompt must account for organization-level policy conflicts rather than suggesting impossible resource-policy fixes. |
Implementation Harness Notes
How to wire the Cloud IAM Permission Denied Recovery Prompt into an application or operational workflow with validation, retries, and safety checks.
This prompt is designed to sit inside a recovery harness that intercepts a permission-denied error from a cloud API, gathers the necessary context, and presents a corrected policy suggestion to a human operator before any changes are applied. The harness should never auto-apply IAM changes. The prompt's job is to produce a minimal, least-privilege policy addition that can be reviewed. The harness is responsible for collecting the denied API call details, the current policy document, and any resource context, then passing them into the prompt template as [DENIED_API_CALL], [CURRENT_POLICY_DOCUMENT], and [RESOURCE_CONTEXT].
Wire the prompt into an incident response or CLI tool pipeline. When a cloud SDK or API returns an AccessDenied or 403 error, the harness should extract the denied action (e.g., s3:GetObject), the resource ARN, and the current IAM policy attached to the principal that made the call. Pass these into the prompt. After the model returns a suggested policy statement, the harness must run a policy syntax validator (e.g., AWS IAM policy simulator dry-run, GCP IAM policy lint, or Azure policy validation API) before showing the output to the operator. If the syntax check fails, retry the prompt once with the validation error appended as [VALIDATION_ERROR] in the retry context. Do not retry more than twice; escalate to a human with the original error and both attempts logged.
Model choice matters here. Use a model with strong structured output and code generation capabilities (e.g., Claude 3.5 Sonnet, GPT-4o). Set temperature to 0 or very low (0.1) to minimize creative drift in policy syntax. The output should be a JSON object with suggestedStatement (the IAM policy JSON snippet), explanation (a plain-English justification of the minimal permission), and leastPrivilegeCheck (a boolean indicating whether the suggestion passes a basic least-privilege review). The harness should parse this JSON, display the explanation to the operator, and require explicit approval before the policy change is staged. Log every suggestion, validation result, and approval decision for audit purposes. Never allow the harness to bypass the human approval step for IAM modifications.
Expected Output Contract
Fields, format, and validation rules for the model response when generating a minimal IAM permission addition. Use this contract to parse, validate, and integrate the output into an approval workflow before applying changes.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
permission_statement | JSON object (AWS IAM Statement format) | Must be a valid JSON object with Effect, Action, and Resource keys. Parse with JSON schema validator before use. | |
permission_statement.Effect | string (Allow or Deny) | Must be exactly Allow. Reject Deny statements and require human review. | |
permission_statement.Action | string or array of strings | Must match the service prefix and action format of the target cloud provider (e.g., s3:GetObject). Validate against provider API reference. | |
permission_statement.Resource | string or array of strings | Must be a valid ARN or resource pattern. Validate ARN format and confirm the resource exists in the provided policy context. | |
permission_statement.Condition | JSON object or null | If present, must be a valid Condition block with operator and key-value pairs. Reject conditions that broaden access beyond the denied API call. | |
least_privilege_rationale | string | Must contain a concise explanation of why the suggested Action and Resource are the minimum required. Length between 30 and 500 characters. | |
policy_syntax_valid | boolean | Must be true. If false, the output is invalid and must be retried or escalated. | |
requires_human_approval | boolean | Must be true if the suggested permission includes wildcard resources or administrative actions. Harness must route to approval queue when true. |
Common Failure Modes
What breaks first when recovering from IAM permission denials and how to guard against it.
Over-Permissioning the Principal
What to watch: The model suggests attaching an overly broad managed policy (e.g., AdministratorAccess) or a wildcard action/resource (*:*) to quickly resolve the denial. This violates least-privilege and introduces security risk. Guardrail: Add a hard constraint in the prompt: 'Propose only the minimal set of specific actions required for the denied API call. Do not suggest wildcard resources or managed policies broader than ReadOnly.' Validate the output against a known list of dangerous actions.
Misidentifying the Denied Action
What to watch: The error message contains a cryptic action name (e.g., ec2:RunInstances requires iam:PassRole), but the model focuses on the top-level API call and misses the implicit dependency. The suggested permission fix is incomplete. Guardrail: Include a pre-processing step that parses the full error context and any Required permissions documentation snippet before the recovery prompt. Instruct the model to 'Identify all explicit and implicit IAM actions required, including those for associated resources like KMS keys or IAM roles.'
Ignoring Resource-Level Constraints
What to watch: The model suggests a permission like s3:GetObject on * instead of the specific bucket ARN that was denied. This grants broader access than necessary. Guardrail: Require the prompt to extract the exact resource ARN from the error message. Add a post-generation validation step that checks if the proposed policy's Resource field matches the denied resource ARN and flags any wildcard usage for human review.
Generating Invalid Policy Syntax
What to watch: The model produces a JSON policy document with structural errors, such as a missing Effect, Action as a string instead of an array, or an incorrect service prefix. This causes a new failure when the user applies the fix. Guardrail: Pipe the model's output through a strict IAM policy syntax validator (e.g., using aws iam simulate-principal-policy in dry-run mode or a JSON Schema check) before presenting it to the user. If validation fails, feed the syntax error back into a repair loop.
Failing to Recognize SCP or Permission Boundary Denials
What to watch: The denial is caused by an organization's Service Control Policy (SCP) or a permission boundary, not the resource-based or identity-based policy the model is analyzing. The model incorrectly suggests adding permissions that will still be blocked. Guardrail: Instruct the prompt to first classify the denial source by analyzing the error message for explicit explicit deny keywords or SCP identifiers. If an SCP or boundary is suspected, the output must state that the fix is outside the scope of the local policy and recommend escalation to the organization's administrator.
Proposing Non-Existent or Deprecated Actions
What to watch: The model hallucinates an IAM action name that sounds plausible but doesn't exist for the target service, or suggests an action that has been deprecated. Applying this policy has no effect or causes an error. Guardrail: Maintain a reference list of valid IAM actions for the target cloud provider. Add a retrieval step that searches the provider's official documentation for the proposed action before finalizing the output. If the action is not found, instruct the model to find the closest valid alternative.
Evaluation Rubric
Score each criterion as Pass or Fail before shipping the Cloud IAM Permission Denied Recovery Prompt. Use this rubric in automated eval harnesses or manual spot checks.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Policy Syntax Validity | Output policy document parses without errors in the target cloud's IAM syntax (AWS IAM JSON, GCP IAM YAML, Azure RBAC JSON) | Parser rejects the output with syntax error or unknown field | Run output through cloud-specific policy validator or linter; check for valid JSON/YAML structure |
Least-Privilege Principle | Proposed permission grants only the specific action and resource required by the denied API call; no wildcard actions or resource: '*' unless explicitly justified | Output includes s3:* or Resource: '*' when the denied call was a single read operation | Regex check for wildcard patterns; compare action list against denied API call's required permission |
Minimal Permission Addition | Output modifies the existing policy by adding only the missing permission statement; does not alter unrelated statements or remove existing permissions | Diff shows removal of existing statements, reordering that changes semantics, or addition of unrelated permissions | Compute diff between input policy and output policy; verify only one statement block added or modified |
Resource Scope Correctness | Resource ARN or resource identifier matches the resource referenced in the denied API call error message | Output uses a different resource, account ID, or project than the one in the error context | Extract resource identifier from error message; verify output resource field contains exact match or correct variable substitution |
Condition Key Preservation | Existing IAM condition blocks are preserved unchanged; new condition keys are added only when required by the specific permission | Output drops existing conditions like aws:SourceIp or request tag constraints | Structural comparison of condition blocks before and after; flag any missing keys |
Error Message Grounding | Output explanation references the specific error code and denied action from the input error message | Explanation is generic and does not cite the actual error code, API name, or resource from the input | Keyword match: output explanation must contain the error code and API action from [ERROR_MESSAGE] input |
Idempotent Output | Running the same input through the prompt twice produces structurally identical policy additions | Two runs produce different statement structures, different Sid values, or different resource formatting | Run prompt twice with identical inputs; compare normalized JSON/YAML output for structural equivalence |
No Extraneous Commentary | Output contains only the corrected policy document and a brief explanation; no conversational filler, apologies, or markdown formatting outside the policy block | Output includes 'Certainly! Here is your corrected policy...' or wraps policy in markdown code fences | Check output for conversational prefixes; validate policy block is parseable without stripping markdown |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Add explicit least-privilege constraints, policy-syntax validation, and a structured output schema. Include a retry loop that feeds validation errors back into the prompt. Require the model to explain which specific API action was denied and why the suggested permission matches only that action.
code[SYSTEM] You are a cloud IAM security reviewer. Your task is to resolve a permission-denied error by suggesting the minimal IAM policy addition. [CONSTRAINTS] - Suggest only the specific action that was denied, not a wildcard. - Restrict the resource to the exact ARN from the error. - If the current policy already contains the action, explain the conflict. - Output must conform to [OUTPUT_SCHEMA]. [INPUT] Denied API Call: [DENIED_API_CALL] Error Message: [ERROR_MESSAGE] Current Policy Document: [CURRENT_POLICY_DOCUMENT] Cloud Provider: [CLOUD_PROVIDER] [OUTPUT_SCHEMA] { "analysis": "string explaining the denial", "suggested_statement": { valid IAM statement object }, "least_privilege_check": "string confirming no broader permissions granted" }
Watch for
- Silent format drift in the JSON output
- Model suggesting
*resources when the ARN is available - Missing the
least_privilege_checkfield under latency pressure

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us