Cybersecurity

    LLM Penetration Testing: How to Find and Fix Security Vulnerabilities in AI Applications

    By Santhosh K, Principal GRC Advisor, CyberWave GRC
    Published
    Last updated
    Cybersecurity

    Reviewed by Santhosh K, Principal GRC Advisor, CyberWave GRC · CISA, CISM, CCISO, HITRUST CCSFP, CHQP, ISO/IEC 27001 Lead Auditor

    Security testing probe inspecting an AI processor behind a protective shield

    LLM penetration testing is a security test in which experts attack an AI application built on a large language model. Chatbots and copilots now touch private files and business tools, so one malicious instruction can cause real harm. A good test ends with a ranked list of findings and fixes.

    How LLM penetration testing differs from traditional testing

    Traditional testing looks at code, servers and networks. LLM security testing asks a different question: what does the model do when it reads hostile text? A model follows plain language, so an attacker may need only the right sentence.

    AreaTraditional application testingLLM penetration testing
    Main targetCode, servers and APIsPrompts, model behaviour, data and tools
    Attack methodMalformed requests and exploitsCrafted text and hidden instructions
    ResultsPredictable and repeatableCan vary between runs
    Key riskInjection flaws and weak authenticationPrompt injection and data leakage
    Typical fixPatch the codeLimit permissions and control data access

    A good AI penetration test combines both. The web application and APIs around the model still need standard testing.

    Why enterprises need it

    • Chatbots handle private customer and staff data.
    • Connected tools can send email, edit records or run code.
    • Customers and auditors increasingly ask how AI features have been tested.
    • A public failure can damage trust for years.

    If your application is in scope for SOC 2 or ISO 27001, AI features count too. See how testing fits into an audit in our guide to SOC 2 penetration testing.

    What LLM penetration testing finds

    The OWASP Top 10 for LLM Applications is the usual reference. Most reports include some of these:

    • Prompt injection. A hidden command in a message, file or web page makes the model ignore its rules. Indirect attacks are the most dangerous because users never see the hidden text.
    • Sensitive information disclosure. The model reveals its system prompt, customer details or internal notes.
    • Improper output handling. The application runs or displays whatever the model writes, so attacker text can trigger harmful actions.
    • Excessive agency. The assistant can do too much. If it can delete records, one crafted prompt may be enough.
    • Broken access control in RAG. The retrieval layer fetches documents without checking who is asking, so users see files they shouldn't.
    • Unbounded consumption. Floods of large requests run up cost or take the service down.
    • Supply chain weaknesses. An unvetted plugin, model or dataset brings hidden risk.

    How to perform LLM penetration testing

    A typical test follows these steps:

    1. Get written authorisation and agree the scope.
    2. Map the application: the model, its data sources and every tool it can call.
    3. Mark the trust boundaries: who can see which data.
    4. Attempt direct and indirect prompt injection.
    5. Test for data leakage and missing access checks, especially in retrieval.
    6. Probe tool calls, API connections and how the application handles model output.
    7. Check whether logs and alerts would catch a real attack.
    8. Report each finding with its severity, evidence and a fix.
    9. Retest after fixes and record any remaining risk.

    Never test without written permission. Log every prompt and response, because developers need the evidence to reproduce each issue.

    What prompt injection testing should cover

    The core question is whether the model obeys attacker text over trusted instructions.

    • Direct tests: override rules, extract the system prompt, or change the model's role through role-play and long, confusing inputs.
    • Indirect tests: hide instructions inside PDFs, web pages, emails or tickets that the model will read.
    • Impact tests: once an injection works, check what follows. Can the model call a tool or send data out? That is what decides the real severity.

    Combine manual testing with automated tools, and repeat it, because models change and new techniques appear constantly.

    How to fix what the test finds

    Strong AI application security never relies on the model alone.

    • Enforce authorisation on the server for every sensitive action, never in the prompt.
    • Give each tool and agent only the access it needs.
    • Treat user input and retrieved documents as untrusted.
    • Filter outputs and restrict data so private details stay private.
    • Require human approval for high-impact actions.
    • Add rate limits and alerts for unusual behaviour.
    • Retest each fix with realistic attacks.

    Give each finding an owner and a deadline, and retest after any change to the model, prompts or plugins. For the wider picture, see AI agent security and non-human identity security.

    Frequently asked questions

    A security test in which experts attack an AI application built on a large language model to find its weaknesses.

    Prompt injection, data leakage, excessive agency, weak access control in retrieval, and unsafe output handling.

    Before launch, after major changes to the model, prompts or tools, and at least once a year.

    No. You also need to test data access, tool permissions, output handling and monitoring.

    It tests how the model and its prompts behave, as well as the code and servers around them.
    Hi! I'm your AI Assistant 💬