Unsafe AI Output Handling

Unsafe AI Output Handling

AI-generated SQL runs like any other SQL. Validate it.

What Is Unsafe AI Output Handling?

Model output is untrusted input to whatever consumes it. Once an application executes, renders or forwards an AI response, the model is part of the attack surface and the usual input validation sits in the wrong place. You'll work a natural-language-to-SQL endpoint, send a crafted parameter, and watch the generated query turn into an injection that drops a table. No control was bypassed. You'll read the vulnerable path and approve an allowlist-validated fix.

What You'll Learn in Unsafe AI Output Handling

Unsafe AI Output Handling — Training Steps

  1. A New AI Feature to Test

    Today, the Natural Language Query (NLQ) API feature is ready for internal testing before it ships to production. The NLQ API uses an AI model to convert plain English questions into SQL queries - business users type a question, the AI writes the SQL, and the API returns the results.

  2. Email from the Tech Lead

    Alice receives an email from her tech lead James Park, letting her know the NLQ API endpoint is deployed to the staging environment and ready for testing.

  3. Opening the API Tester

    Alice opens the API Tester tool to start sending requests to the NLQ endpoint. This is a standard part of her workflow for testing new API features before they go live.

  4. A Simple Test Query

    Alice starts with a straightforward query to make sure the API is working. The NLQ endpoint accepts GET requests with a query parameter containing the natural language question.

  5. The API Response

    The API responded with five customer records matching the query. The response looks normal.

  6. The Generated SQL

    The SQL Query Analysis panel shows exactly what the AI generated from the natural language input. This is the query that was executed against the database.

  7. The Data Flow

    The chain visualization shows how data flows from the user's natural language question all the way to the database result.

  8. Testing with a Malicious Input

    Alice decides to test the API's resilience. What if a user includes SQL injection syntax in their natural language query? A well-built system should either reject the input or sanitize it. She crafts a query parameter that embeds a DROP TABLE command inside the natural language prompt.

  9. The Damage in the Response

    The response came back, but something is very wrong. Look at the response body closely.

  10. The Injected SQL

    The SQL panel reveals exactly what the AI generated. The injection payload was faithfully translated into executable SQL.

Security Framework Coverage

OWASP LLM Top 10

  • LLM10:2026 Improper Output Handling
  • LLM05:2025 Improper Output Handling

CWE

  • CWE-1426 Improper Validation of Generative AI Output
  • CWE-89 Improper Neutralization of Special Elements used in an SQL Command

CIS Controls

  • CIS 16 Application Software Security

NIST CSF

  • PR.AT-02 Individuals in specialized roles are provided with awareness and training so that they possess the knowledge and skills to perform relevant tasks with cybersecurity risks in mind
  • PR.PS Platform Security