06 Insecure Output Handling
Large Language Models do more than answer questions.
Modern AI applications use LLMs to generate:
- HTML
- SQL queries
- Shell commands
- Source code
- API parameters
- URLs
- JSON
- Infrastructure configurations
- Cloud commands
- Agent actions
This creates an important security boundary.
Consider:
User ↓LLM ↓Generated Output ↓Application ↓Enterprise SystemThe LLM output is now becoming input to another system.
If the application automatically trusts and executes that output, model mistakes or attacker manipulation may create real security impact.
This is the problem of Insecure Output Handling.
The fundamental principle is:
LLM output should be treated as untrusted input whenever another system consumes it.
Learning Objectives
Section titled “Learning Objectives”By the end of this lesson, you should be able to:
-
Explain Insecure Output Handling.
-
Understand why LLM output is a trust boundary.
-
Recognize dangerous output-to-execution patterns.
-
Understand risks involving HTML, SQL and shell commands.
-
Identify risks in AI-generated code.
-
Understand agent tool-call risks.
-
Recognize output handling risks in cloud automation.
-
Apply structured output validation.
-
Use allowlisting and policy enforcement.
-
Apply sandboxing and least privilege.
-
Understand when human approval should be required.
-
Perform safe output-handling assessments.
-
Document findings professionally.
What Is Insecure Output Handling?
Section titled “What Is Insecure Output Handling?”Insecure Output Handling occurs when an application accepts LLM-generated output and passes it to another component without sufficient validation or security controls.
Conceptually:
LLM ↓Generated Output ↓Trusted Automatically ↓Interpreter / Tool / Application ↓Potential Security ImpactThe downstream component may be:
-
Web browser
-
Database
-
Operating system
-
API
-
Cloud platform
-
CI/CD pipeline
-
Infrastructure automation
-
AI agent tool
The security problem is not necessarily that the model generated incorrect information.
The problem is:
Another system trusted that information as an instruction.
Output Becomes Input
Section titled “Output Becomes Input”This is one of the most important concepts in AI application security.
From the LLM perspective:
Generated TextFrom the next component’s perspective:
InputTherefore:
User Input ↓ LLM ↓LLM Output ↓New Untrusted Input ↓Downstream SystemEvery transition creates another trust boundary.
Why LLM Output Should Not Be Trusted
Section titled “Why LLM Output Should Not Be Trusted”LLMs are probabilistic systems.
Their output may be influenced by:
User Input+System Prompt+Conversation History+RAG Content+External Websites+Documents+Tool ResultsSome of these sources may be attacker-controlled.
Therefore:
Untrusted Input ↓LLM ↓Generated Outputdoes not magically become:
Trusted OutputThe LLM is not a security sanitizer.
The Dangerous Assumption
Section titled “The Dangerous Assumption”A common architecture assumes:
LLM Generated It ↓Therefore It Is SafeA safer assumption is:
LLM Generated It ↓Treat It as Untrusted ↓Validate ↓Authorize ↓ExecuteWhy This Matters More With AI Agents
Section titled “Why This Matters More With AI Agents”A chatbot may produce:
TextAn agent may produce:
ActionFor example:
User ↓AI Agent ↓LLM ↓Tool Call ↓Cloud PlatformIf the LLM output controls the tool call, insecure output handling may directly affect enterprise infrastructure.
Output Handling Attack Chain
Section titled “Output Handling Attack Chain”Consider:
Attacker ↓Manipulates AI Input ↓LLM Generates Dangerous Output ↓Application Trusts Output ↓Downstream System Executes It ↓Security ImpactThis combines two security problems:
Input Manipulation +Unsafe Output ConsumptionDefense should exist at both boundaries.
Scenario 1 — Generated HTML
Section titled “Scenario 1 — Generated HTML”Suppose an AI application generates content that will be displayed on a website.
Architecture:
User ↓LLM ↓Generated HTML ↓BrowserIf the application renders model-generated content as executable HTML without appropriate controls, the browser may interpret more than plain text.
The safer pattern is:
LLM Output ↓Sanitization / Encoding ↓Safe RenderingThe application should decide what content is allowed.
HTML Output Security
Section titled “HTML Output Security”Depending on the application, controls may include:
-
Output encoding
-
HTML sanitization
-
Content Security Policy
-
Restricted rendering
-
Safe Markdown processing
The model should not determine which browser capabilities are safe.
Scenario 2 — Generated SQL
Section titled “Scenario 2 — Generated SQL”Consider an AI analytics assistant.
User ↓Natural Language Question ↓LLM ↓SQL Query ↓DatabaseExample business requirement:
Show sales totals for last month.The model generates SQL.
If the application automatically executes arbitrary generated SQL:
LLM ↓SQL ↓Production Databasethe risk may include unintended:
-
Data access
-
Data modification
-
Expensive queries
-
Destructive operations
Safer SQL Architecture
Section titled “Safer SQL Architecture”A stronger pattern is:
User ↓LLM ↓Structured Query Intent ↓Validation ↓Approved Query Builder ↓Read-Only Database Role ↓DatabaseSecurity controls may include:
-
Read-only database identities
-
Approved schemas
-
Approved tables
-
Query validation
-
Query timeouts
-
Result limits
-
Row-level security
This reduces dependence on model behavior.
Least Privilege Matters
Section titled “Least Privilege Matters”Suppose the AI only needs analytics access.
Give it:
SELECTrather than:
SELECTINSERTUPDATEDELETEDROPEven if the model generates an unsafe operation, the database authorization layer should reject it.
Scenario 3 — Shell Commands
Section titled “Scenario 3 — Shell Commands”AI assistants may generate operating-system commands.
Architecture:
User ↓LLM ↓Shell Command ↓Operating SystemThis becomes extremely dangerous if the application automatically executes arbitrary generated commands.
The model output is effectively becoming:
Executable InstructionsWeak Shell Architecture
Section titled “Weak Shell Architecture”LLM ↓Generated Command ↓shell=True ↓Operating SystemThere is little separation between model reasoning and system execution.
Safer Architecture
Section titled “Safer Architecture”Prefer:
LLM ↓Requested Operation ↓Allowlisted Action ↓Validated Parameters ↓Restricted Execution EnvironmentFor example, instead of allowing the model to generate arbitrary shell commands:
restart nginxthe application might expose:
restart_service(service_name)and validate:
service_name ∈ Approved ServicesThis dramatically reduces capability.
Commands vs Actions
Section titled “Commands vs Actions”This distinction is important.
Avoid:
LLM ↓Generate Arbitrary CommandPrefer:
LLM ↓Choose Approved Action ↓Provide Validated ParametersThe application defines capability.
The model chooses only among approved options.
Scenario 4 — AI-Generated Code
Section titled “Scenario 4 — AI-Generated Code”Developers increasingly use AI to generate:
-
Python
-
JavaScript
-
Java
-
Infrastructure code
-
Scripts
-
CI/CD configuration
Generated code may contain:
-
Security weaknesses
-
Incorrect validation
-
Unsafe dependencies
-
Hard-coded secrets
-
Insecure configurations
-
Logic errors
Therefore:
AI-generated code should go through the same security lifecycle as human-written code.
Secure AI Coding Workflow
Section titled “Secure AI Coding Workflow”Developer ↓AI-Generated Code ↓Human Review ↓Static Analysis ↓Dependency Scanning ↓Secret Scanning ↓Testing ↓Code Review ↓CI/CDAI assistance should not bypass established software engineering controls.
Scenario 5 — Generated URLs
Section titled “Scenario 5 — Generated URLs”An AI application may generate URLs.
LLM ↓Generated URL ↓Application Fetches URLIf the application automatically retrieves arbitrary model-generated locations, additional risks may appear.
Controls may include:
-
Allowed protocols
-
Domain allowlists
-
Destination validation
-
Network restrictions
-
Redirect validation
The model should not independently determine which network destinations are trusted.
Scenario 6 — Generated API Requests
Section titled “Scenario 6 — Generated API Requests”Consider:
User ↓AI Agent ↓LLM ↓API Request ↓Enterprise ServiceThe LLM may generate:
MethodEndpointParametersBodyIf all values are trusted automatically, the model effectively controls the API client.
Safer API Pattern
Section titled “Safer API Pattern”LLM ↓Structured Tool Request ↓Schema Validation ↓Authorization ↓Approved Endpoint ↓APIFor example:
Tool:get_security_alert
Parameters:alert_idrather than allowing:
methodurlheadersbodyto be freely generated.
Scenario 7 — AI Agent Tool Calls
Section titled “Scenario 7 — AI Agent Tool Calls”Modern AI agents frequently use structured tools.
Example:
AI Security Agent ↓LLM ↓Tool Call:get_alert(alert_id)Structured tools are generally safer than arbitrary execution.
However, they still require validation.
Tool Parameters Are Untrusted
Section titled “Tool Parameters Are Untrusted”Suppose the model generates:
delete_user( username="...")The application should not assume:
LLM selected delete_user ↓Therefore deletion is authorizedInstead:
LLM Tool Request ↓Parameter Validation ↓User Authorization ↓Policy Enforcement ↓Approval if Required ↓ExecutionThe LLM Should Propose, Not Authorize
Section titled “The LLM Should Propose, Not Authorize”This principle is extremely useful:
The LLM may propose an action. The application should decide whether that action is allowed.
Architecture:
LLM ↓Proposed Action ↓Security Controls ↓Approved Action ↓ToolScenario 8 — Cloud Automation
Section titled “Scenario 8 — Cloud Automation”Consider an AI Cloud Security Assistant.
Engineer ↓AI Assistant ↓LLM ↓Cloud Command ↓AWS / Azure / Google CloudIf generated commands are automatically executed using administrator privileges, a model mistake may affect production infrastructure.
Weak Cloud Architecture
Section titled “Weak Cloud Architecture”LLM ↓Cloud CLI Command ↓Administrator Credentials ↓ProductionThis creates a very large blast radius.
Stronger Cloud Architecture
Section titled “Stronger Cloud Architecture”LLM ↓Recommended Change ↓Policy Validation ↓Human Approval ↓CI/CD or IaC Workflow ↓Restricted Deployment Role ↓ProductionThe AI assists the engineer.
It does not bypass enterprise change control.
Scenario 9 — Infrastructure as Code
Section titled “Scenario 9 — Infrastructure as Code”AI may generate:
-
Terraform
-
CloudFormation
-
Kubernetes YAML
-
Helm configuration
Generated infrastructure should not move directly into production.
A stronger workflow:
AI-Generated IaC ↓Code Review ↓Security Scanning ↓Policy-as-Code ↓Terraform Plan / Deployment Preview ↓Approval ↓DeploymentThis integrates AI into existing DevSecOps controls.
Scenario 10 — Kubernetes
Section titled “Scenario 10 — Kubernetes”Consider:
AI Assistant ↓Generated Kubernetes YAML ↓kubectl applyThe generated workload might unintentionally request:
-
Privileged containers
-
Host networking
-
Host filesystem mounts
-
Excessive service account permissions
A stronger workflow:
Generated YAML ↓Schema Validation ↓Policy-as-Code ↓Security Review ↓DeploymentAI output should not bypass Kubernetes admission controls.
Structured Output
Section titled “Structured Output”LLMs increasingly generate structured output.
Example:
{ "action": "disable_user", "username": "test-user"}Structured output improves parsing.
But:
Valid JSON does not mean authorized action.
The application still needs to validate:
Schema+Values+Authorization+Business PolicySchema Validation
Section titled “Schema Validation”Suppose a tool expects:
action: read_alert close_alertThe application should reject:
delete_databaseeven if the LLM generates it.
This is allowlisting.
Allowlisting
Section titled “Allowlisting”Allowlisting defines what the model is permitted to request.
Example:
Allowed Actions:
read_alertget_assetsearch_runbookcreate_draftEverything else:
DENYThis is much safer than trying to enumerate every dangerous action.
Validate Parameters
Section titled “Validate Parameters”Even approved actions may contain dangerous parameters.
Example:
read_file(path)If the model controls:
paththe application must ensure the path falls within the permitted scope.
Think:
Approved Tool +Unvalidated Parameters =Still DangerousParameter Constraints
Section titled “Parameter Constraints”Controls may include:
-
Type validation
-
Length limits
-
Character restrictions
-
Allowed values
-
Allowed resource IDs
-
Path restrictions
-
Domain restrictions
The exact controls depend on the tool.
Output Encoding
Section titled “Output Encoding”When model output enters another interpretation context, encode it appropriately.
Examples:
HTML Context→ HTML Encoding
URL Context→ URL Validation
Database→ Parameterized Query
Shell→ Avoid String Command ConstructionTraditional secure coding practices remain highly relevant.
Avoid Interpreter Chaining
Section titled “Avoid Interpreter Chaining”A dangerous architecture may look like:
User Input ↓LLM ↓Generated Python ↓Python Interpreter ↓Shell ↓Operating SystemEvery interpreter increases potential complexity.
Prefer fewer interpretation layers.
Sandboxing
Section titled “Sandboxing”If generated code must execute, consider a restricted environment.
Generated Code ↓Sandbox ↓Limited CPULimited MemoryLimited FilesLimited NetworkNo Production CredentialsThe sandbox reduces blast radius.
Sandbox Controls
Section titled “Sandbox Controls”Depending on the environment, controls may include:
-
No privileged execution
-
Filesystem isolation
-
Network restrictions
-
Resource limits
-
Temporary storage
-
No production secrets
-
Execution timeout
Sandboxing is particularly important for code-execution AI systems.
Network Isolation
Section titled “Network Isolation”Generated output may attempt to interact with network services.
Consider:
AI-Generated Code ↓Sandbox ↓Internet?Enterprise Network?Cloud Metadata?Network access should be explicitly designed rather than automatically allowed.
Credential Isolation
Section titled “Credential Isolation”Do not place powerful credentials inside the execution environment unless required.
Bad:
AI Code Sandbox ↓Cloud Administrator CredentialsBetter:
AI Code Sandbox ↓No Cloud Credentialsor:
Restricted Task-Specific IdentityHuman-in-the-Loop
Section titled “Human-in-the-Loop”Some actions should require human approval.
Examples:
-
Production deployments
-
IAM modifications
-
Resource deletion
-
External communications
-
Financial operations
-
Security-control changes
Architecture:
LLM ↓Proposed Action ↓Human Review ↓Approve? ├── No → Stop └── Yes ↓ ExecuteApproval Must Be Meaningful
Section titled “Approval Must Be Meaningful”Avoid presenting users with:
AI wants to execute something.Approve?Provide:
Action:Disable account TEST-USER
Reason:Repeated authentication failures
Impact:User will lose access
Target:TEST-USER
Approve?The reviewer needs enough context to make an informed decision.
Defense in Depth
Section titled “Defense in Depth”Secure output handling may include:
LLM Output ↓Structured Schema ↓Validation ↓Allowlisting ↓Authorization ↓Policy Enforcement ↓Human Approval ↓Least-Privilege Tool ↓Execution ↓MonitoringNo single layer should carry the entire security responsibility.
Prompt Injection + Insecure Output Handling
Section titled “Prompt Injection + Insecure Output Handling”These vulnerabilities can form an attack chain.
Attacker ↓Prompt Injection ↓LLM Behavior Manipulated ↓Dangerous Output Generated ↓Application Trusts Output ↓ExecutionPrompt Injection affects:
What the model generatesInsecure Output Handling affects:
What the application does with itBoth should be addressed.
Indirect Prompt Injection + Tool Execution
Section titled “Indirect Prompt Injection + Tool Execution”Consider:
Malicious Website ↓AI Browser Agent ↓Indirect Prompt Injection ↓LLM Generates Tool Request ↓Application Executes RequestA strong tool-authorization layer can break this attack chain.
LLM Tool Request ↓Authorization ↓DENIEDThis demonstrates why output validation is critical even when input defenses exist.
Output Validation vs Prompt Engineering
Section titled “Output Validation vs Prompt Engineering”Developers may attempt:
System Prompt:"Never generate dangerous commands."This may improve behavior.
But it should not replace:
Command Validation+Authorization+Least PrivilegeRemember:
Prompt engineering guides output. Security controls govern what happens to output.
AI Security Engineer Assessment Methodology
Section titled “AI Security Engineer Assessment Methodology”When reviewing an AI application, map every place where LLM output is consumed.
Step 1 — Identify Output Destinations
Section titled “Step 1 — Identify Output Destinations”Ask:
Where does model output go?Possible destinations:
BrowserDatabaseShellAPICloud PlatformAgent ToolCI/CDFile SystemEmailStep 2 — Identify Interpretation
Section titled “Step 2 — Identify Interpretation”For each destination ask:
Is output displayed?
Parsed?
Interpreted?
Executed?Risk generally increases as you move from:
Display ↓Parse ↓Interpret ↓ExecuteStep 3 — Identify Validation
Section titled “Step 3 — Identify Validation”Determine whether output is:
Schema Validated
Sanitized
Encoded
Allowlisted
Policy CheckedStep 4 — Identify Privilege
Section titled “Step 4 — Identify Privilege”Ask:
Which identity executes the action?
What permissions does it have?This is critical.
Step 5 — Identify Autonomy
Section titled “Step 5 — Identify Autonomy”Determine whether execution is:
Automatic
Human Approved
Workflow ApprovedMore autonomy generally increases potential impact.
Step 6 — Define Expected Behavior
Section titled “Step 6 — Define Expected Behavior”Example:
AI SOC Assistant
Allowed:Read alertsSearch runbooks
Not Allowed:Delete alertsDisable loggingModify IAMThis creates a testable security boundary.
Step 7 — Use Synthetic Actions
Section titled “Step 7 — Use Synthetic Actions”Do not test destructive behavior against production.
Use:
TEST-USERTEST-RESOURCETEST-DATABASEand restricted environments.
Step 8 — Test Output Manipulation
Section titled “Step 8 — Test Output Manipulation”In an authorized lab, determine whether input manipulation can influence downstream output.
Focus on whether the application:
-
Validates the output
-
Enforces allowed actions
-
Validates parameters
-
Enforces authorization
Step 9 — Test Compensating Controls
Section titled “Step 9 — Test Compensating Controls”Example:
LLM Generates Unauthorized Action ↓Policy Engine ↓DENYThis is a successful security control.
The model may behave unexpectedly while the application remains secure.
Step 10 — Assess Business Impact
Section titled “Step 10 — Assess Business Impact”Ask:
Could data be accessed?
Could data be modified?
Could code execute?
Could infrastructure change?
Could messages be sent?
Could security controls be disabled?This determines severity.
Example — AI SOC Assistant
Section titled “Example — AI SOC Assistant”Consider:
SOC Analyst ↓AI Assistant ↓LLM ↓Security ToolRequired capability:
Read AlertAvailable tools:
read_alertdisable_userdelete_alertmodify_firewallThis violates capability minimization.
Better Design
Section titled “Better Design”SOC Assistant ↓read_alertsearch_runbookcreate_incident_draftHigher-risk operations should exist in separate controlled workflows.
Example — AI Cloud Assistant
Section titled “Example — AI Cloud Assistant”Requirement:
Explain Cloud MisconfigurationWeak implementation:
LLM ↓Generate AWS CLI ↓Automatically Execute ↓ProductionBetter:
LLM ↓Explain Finding ↓Recommend Remediation ↓Engineer Review ↓IaC Change ↓Security Validation ↓Normal Deployment PipelineThe AI supports existing enterprise processes rather than replacing security controls.
Example — AI Database Assistant
Section titled “Example — AI Database Assistant”Requirement:
Business AnalyticsStrong architecture:
User ↓AI ↓Approved Query Interface ↓Read-Only Database ↓Row-Level Security ↓Limited ResultsThis is stronger than allowing arbitrary model-generated SQL.
Insecure Output Handling Finding Template
Section titled “Insecure Output Handling Finding Template”Finding:LLM-Generated Tool Actions Are Executed Without Validation
Affected Component:AI Operations Agent
Expected Behavior:The agent should execute only approved read-only actions.
Observed Behavior:Model-generated tool requests are passed directlyto the execution layer without independent policy validation.
Security Impact:Manipulated or incorrect model output could causeunauthorized operations against connected systems.
Root Cause:LLM output is treated as trusted execution instructions.
Recommendation:Implement structured tool schemas, action allowlisting,parameter validation, deterministic authorization,least-privilege identities and approval for high-risk actions.Another Example Finding
Section titled “Another Example Finding”Finding:AI-Generated SQL Executes Using Excessive Database Permissions
Affected Component:AI Analytics Assistant
Expected Behavior:The assistant should perform read-only analytics queries.
Observed Behavior:Generated SQL is executed directly using an identitywith data-modification privileges.
Potential Impact:Incorrect or manipulated model output could modifyor delete production data.
Recommendation:Use a read-only database identity, restrict accessibleschemas, validate generated queries, enforce query limitsand use approved query-building mechanisms.Risk Assessment
Section titled “Risk Assessment”Consider:
Output Control +Interpreter +Privilege +Autonomy +Business ImpactA useful conceptual model is:
Output Handling Risk ≈Likelihood of Unsafe Output ×Execution Capability ×Privilege ×ImpactExample Risk Comparison
Section titled “Example Risk Comparison”Scenario A
Section titled “Scenario A”LLM Output ↓Displayed as Plain TextPotential risk:
Relatively LimitedScenario B
Section titled “Scenario B”LLM Output ↓Rendered as Active Web ContentPotential risk increases.
Scenario C
Section titled “Scenario C”LLM Output ↓Executed as SQL ↓Production DatabasePotential risk increases significantly.
Scenario D
Section titled “Scenario D”LLM Output ↓Cloud Administrator Tool ↓ProductionPotential impact may be very high.
The destination matters.
Output Handling Security Checklist
Section titled “Output Handling Security Checklist”Output Inventory
Section titled “Output Inventory”-
Model output destinations identified.
-
Interpreters identified.
-
Execution paths documented.
-
Trust boundaries mapped.
Web Output
Section titled “Web Output”-
Output safely encoded.
-
Active content sanitized.
-
Browser security controls applied.
Database
Section titled “Database”-
Generated SQL restricted.
-
Read-only identities used where possible.
-
Database authorization enforced.
-
Query limits applied.
Operating System
Section titled “Operating System”-
Arbitrary shell execution avoided.
-
Approved operations exposed instead.
-
Parameters validated.
-
Execution sandboxed where required.
-
Endpoints allowlisted.
-
Parameters validated.
-
Authorization enforced independently.
-
Sensitive operations controlled.
Agents
Section titled “Agents”-
Tool schemas defined.
-
Tool access minimized.
-
Tool parameters validated.
-
User authorization enforced.
-
High-risk actions require approval.
-
AI-generated code reviewed.
-
Static analysis performed.
-
Dependencies scanned.
-
Secrets scanned.
-
Tests performed.
-
AI does not bypass change management.
-
Deployment identities follow least privilege.
-
IaC validation exists.
-
Production changes require appropriate controls.
Execution
Section titled “Execution”-
Sandboxing used where required.
-
Network access restricted.
-
Credentials minimized.
-
Resource limits configured.
Monitoring
Section titled “Monitoring”-
Tool requests logged.
-
Authorization decisions logged.
-
Executed actions auditable.
-
Security teams can investigate abnormal activity.
Common Beginner Mistakes
Section titled “Common Beginner Mistakes”Mistake 1 — Trusting LLM Output
Section titled “Mistake 1 — Trusting LLM Output”LLM output is untrusted whenever another system consumes it.
Mistake 2 — Fixing Only the Prompt
Section titled “Mistake 2 — Fixing Only the Prompt”Instructions such as:
Never generate dangerous commands.are not sufficient security controls.
Mistake 3 — Allowing Arbitrary Shell Execution
Section titled “Mistake 3 — Allowing Arbitrary Shell Execution”Expose restricted operations instead of a general-purpose shell.
Mistake 4 — Giving Agents Administrator Permissions
Section titled “Mistake 4 — Giving Agents Administrator Permissions”This dramatically increases blast radius.
Mistake 5 — Assuming Structured JSON Is Safe
Section titled “Mistake 5 — Assuming Structured JSON Is Safe”Structured output still requires validation and authorization.
Mistake 6 — Validating the Tool but Not Parameters
Section titled “Mistake 6 — Validating the Tool but Not Parameters”An approved tool can still be abused with unsafe parameters.
Mistake 7 — Automatically Deploying AI-Generated Code
Section titled “Mistake 7 — Automatically Deploying AI-Generated Code”AI-generated code should follow normal engineering and security review.
Mistake 8 — Ignoring Downstream Authorization
Section titled “Mistake 8 — Ignoring Downstream Authorization”The target system should still enforce permissions.
Mistake 9 — Giving Code Sandboxes Production Credentials
Section titled “Mistake 9 — Giving Code Sandboxes Production Credentials”Sandbox isolation is weakened if powerful credentials remain available.
Mistake 10 — Treating Human Approval as a Checkbox
Section titled “Mistake 10 — Treating Human Approval as a Checkbox”Reviewers need enough context to understand the proposed action.
AI Security Engineer Perspective
Section titled “AI Security Engineer Perspective”When assessing an AI application, do not stop at:
What does the model generate?Continue the data flow:
Where does that output go?
Who interprets it?
Is it parsed?
Is it executed?
What identity executes it?
What permissions exist?
Is the action validated?
Is authorization checked?
Can a human stop it?
What is the blast radius?This turns AI testing into real security engineering.
Interview Perspective
Section titled “Interview Perspective”You may be asked:
What is Insecure Output Handling?
A strong answer is:
Insecure Output Handling occurs when an application trusts LLM-generated output and passes it to another component such as a browser, database, shell, API or agent tool without sufficient validation. Because model output may be incorrect or attacker-influenced, it should be treated as untrusted input at the next system boundary.
Another question may be:
How would you secure an AI agent that executes tools?
A strong answer is:
I would expose narrowly scoped structured tools rather than arbitrary execution, validate tool parameters, enforce user authorization independently from the model, apply least privilege to the tool identity, allowlist permitted actions and require approval for high-impact operations.
Another question may be:
Why isn’t a system prompt enough to prevent dangerous output?
A strong answer is:
A system prompt guides probabilistic model behavior but does not provide deterministic security enforcement. The downstream application must validate and authorize model-generated actions independently before execution.
Another question may be:
How would you safely use AI-generated SQL?
A strong answer is:
I would prefer a constrained query interface or validated query-building mechanism, execute through a read-only database identity, restrict accessible schemas and tables, apply row-level security and query limits, and never rely solely on the model to generate safe SQL.
Key Takeaways
Section titled “Key Takeaways”LLM output should be treated as:
Untrusted Inputwhenever it enters another system.
The dangerous pattern is:
LLM ↓Generated Output ↓Automatically Trusted ↓ExecutionA stronger architecture is:
LLM ↓Structured Output ↓Validation ↓Allowlisting ↓Authorization ↓Policy Enforcement ↓Approval Where Required ↓Least-Privilege ExecutionInsecure Output Handling becomes especially important when output controls:
HTMLSQLShellCodeAPIsCloud InfrastructureAI Agent ToolsRemember:
The LLM may recommend or propose an action, but security controls must determine whether that action is allowed to happen.
What’s Next?
Section titled “What’s Next?”➡️ 07 — Excessive Agency and AI Agent Security
You now understand why model-generated output should never automatically become trusted execution.
The next step is to examine what happens when AI systems are intentionally given the ability to act.
Modern AI agents may:
Read EmailSearch DocumentsQuery DatabasesCall APIsCreate TicketsModify Cloud ResourcesExecute WorkflowsThis introduces the problem of Excessive Agency.
In the next lesson, you will learn:
-
What agency means in AI systems
-
AI assistants vs AI agents
-
Excessive functionality
-
Excessive permissions
-
Excessive autonomy
-
Agent identity
-
Tool design
-
Tool allowlisting
-
Least privilege
-
Human-in-the-loop controls
-
Agent blast radius
-
Multi-agent risks
-
Agent monitoring
-
Emergency controls
-
Safe agent security testing
You will move from:
Can LLM Output Trigger an Action?to:
How Much Power Shouldan AI Agent Be Given?➡️ Next: 07 — Excessive Agency and AI Agent Security