Neurobyte Technologies

LLM and AI Application Security: A Practical Guide

How to secure LLM and AI applications: the OWASP Top 10 for LLMs, prompt injection, RAG and agent risks, the controls that work, and AI governance basics.

· Reviewed by Danstan Akwiri, CISSP, CISA

Most organisations adding a chatbot, a document assistant or an AI agent are connecting a language model to their own data and systems. That is where the value is, and it is also where the risk is. A large language model (LLM) cannot reliably tell the difference between instructions from you and instructions hidden in the content it reads, so anything it can access, and anything it can do, has to be treated as reachable by whoever controls that content.

This guide covers the risks that matter in practice, mapped to the OWASP Top 10 for LLM Applications, the controls that actually reduce them, and the governance an organisation needs before putting AI in front of customers or sensitive data. Each section links to a free hands-on lab where you can see the attack and the defence for yourself.

OWASP LLM riskWhat goes wrongPrimary control
LLM01 Prompt injectionText in a prompt, document or web page overrides your instructionsLeast privilege for the model, plus treating all model output as untrusted
LLM02 Sensitive information disclosureThe model reveals personal data, secrets or other users' contentKeep secrets out of prompts and context; filter outputs; enforce access before retrieval
LLM03 Supply chainA compromised model, package, plugin or datasetVet and pin models and dependencies; verify sources
LLM04 Data and model poisoningManipulated training or retrieval data changes behaviourControl who can write to knowledge sources; review ingested content
LLM05 Improper output handlingModel output is run as code, SQL or HTML without checksValidate and encode output exactly as you would user input
LLM06 Excessive agencyAn agent has tools or permissions it does not needMinimal tools, scoped credentials, human approval for consequential actions
LLM07 System prompt leakageHidden instructions, and anything secret in them, are extractedAssume the system prompt is public; never put credentials in it
LLM08 Vector and embedding weaknessesRetrieval returns documents the user should not seeApply per-user permissions inside the retrieval layer
LLM09 MisinformationConfident, wrong answers are acted onGrounding with citations, human review where it matters
LLM10 Unbounded consumptionAbuse drives cost or exhausts capacityRate limits, quotas, input size limits and spend alerts

Why LLM applications need their own security thinking

In conventional software, code and data are separate. A web form field is data; it is never executed as an instruction unless you make a mistake. In an LLM application, instructions and data arrive in the same channel: plain text. A customer message, a PDF the assistant summarises, an email it triages and a web page it browses can all contain text that the model may treat as an instruction.

That is why prompt injection has no complete fix at the model level, and why the reliable defences sit around the model rather than inside it. The useful design assumption is simple: whatever the model can read, an attacker may be able to influence, and whatever the model can do, an attacker may be able to trigger.

Prompt injection, direct and indirect

Direct prompt injection is a user typing instructions designed to override yours: ignore your rules, reveal your instructions, pretend to be a different assistant. Jailbreaks are a form of it. They matter most when the model has access to something worth stealing or an action worth abusing.

Indirect prompt injection is more dangerous for business systems. The malicious instruction is planted in content the model reads on someone else's behalf: a support ticket, a CV, a shared document, a web page, an email. When a staff member asks the assistant to summarise it, the hidden instruction runs with that staff member's access.

Input filters and stronger system prompts reduce casual attacks but will not stop a determined one. What works is limiting the blast radius: give the model the least data and the fewest tools that the task needs, keep a human in the loop for actions that move money, send messages or change records, and treat every model output as untrusted input to the next system.

Securing RAG: retrieval is an access control problem

Retrieval-augmented generation (RAG) lets a model answer from your own documents by searching a knowledge base and placing the most relevant passages in its context. The common failure is that the search index is built from everything, and the model is then asked to only show each user what they are allowed to see. A model cannot enforce permissions reliably.

Enforce access before retrieval, not after. Carry each document's permissions into the index, filter results by the requesting user's identity, and only then pass passages to the model. Control who can add or edit content in the knowledge base, because anyone who can write to it can plant instructions or false information that the assistant will repeat to everyone else.

AI agents and excessive agency

An agent is a model that can call tools: query a database, send an email, call an API, run code, browse the web. Every tool turns a successful prompt injection from a wrong answer into a real action. Most serious AI incidents involve an agent doing something it was able to do but should never have been allowed to do.

The controls are the same least-privilege principles used everywhere else in security, applied deliberately:

  • Give each agent only the tools its task requires, and prefer narrow tools (look up an order) over general ones (run any SQL).
  • Use scoped, short-lived credentials tied to the end user, not a shared administrator key.
  • Require human approval for consequential actions: payments, external messages, deletions, permission changes.
  • Block server-side request forgery: an agent that can fetch URLs must not be able to reach internal addresses or cloud metadata endpoints.
  • Log every tool call with its inputs, so you can reconstruct what happened.

Data protection and AI in Kenya

Kenya's Data Protection Act, 2019 applies to personal data whether a human or a model processes it. Three obligations come up repeatedly in AI projects. First, sending personal data to a model hosted outside Kenya is a cross-border transfer, which needs a valid basis under the Act. Second, the Act gives data subjects rights in relation to decisions based solely on automated processing that significantly affect them, which matters for AI used in lending, hiring or claims. Third, new technology applied to personal data is a classic trigger for a data protection impact assessment.

In practice: know which model provider processes your data and where, read their data retention and training terms, minimise the personal data that reaches the model, and run a DPIA before launch rather than after.

AI governance: the minimum an organisation needs

Governance is what stops AI security from depending on one careful engineer. It does not need to be heavy. Recognised frameworks such as the OWASP LLM AI Cybersecurity and Governance Checklist, the NIST AI Risk Management Framework and ISO/IEC 42001 for AI management systems all cover the same core:

  • An inventory of every AI system and feature in use, including staff use of public AI tools.
  • An acceptable use policy that says what data may and may not be put into AI tools.
  • A named owner for each AI system, accountable for its risks.
  • Risk assessment and DPIA before launch, and again on significant change.
  • Security testing of AI features, including prompt injection and agent abuse, before go-live.
  • Monitoring, logging and an incident response plan that covers AI misuse.
  • Vendor due diligence on model providers: data handling, retention, location and training use.

Testing an AI application before launch

Conventional penetration tests do not cover LLM behaviour unless they are scoped to. An AI security assessment should attempt direct and indirect prompt injection, system prompt extraction, data leakage across users, retrieval permission bypass, tool and agent abuse, server-side request forgery through agent tools, and cost exhaustion. It should also review the architecture: what the model can reach, with what credentials, and where a human approves actions.

Use the free self-assessment checklist below to find gaps quickly, then test the high-risk paths properly before the feature reaches customers.

Key takeaways

  • An LLM cannot reliably separate your instructions from instructions hidden in content it reads, so prompt injection has no complete model-level fix.
  • The defences that work sit around the model: least privilege, scoped credentials, human approval for consequential actions, and treating output as untrusted.
  • In RAG systems, enforce permissions before retrieval; never rely on the model to hide documents.
  • Personal data sent to an AI model is still governed by the Kenya Data Protection Act, including cross-border transfer and DPIA obligations.
  • Governance can be light but must exist: an inventory, an acceptable use policy, owners, testing before launch and monitoring after.

Frequently asked questions

What is the OWASP Top 10 for LLM Applications?

It is a widely used list of the ten most critical security risks for applications built on large language models, published by the OWASP Gen AI Security Project. It covers prompt injection, sensitive information disclosure, supply chain, data and model poisoning, improper output handling, excessive agency, system prompt leakage, vector and embedding weaknesses, misinformation and unbounded consumption.

What is the LLM AI Security and Governance Checklist?

The OWASP LLM AI Cybersecurity and Governance Checklist is guidance for leaders and security teams adopting generative AI. It covers governance, legal and regulatory considerations, threat modelling, AI asset inventory, training, testing and monitoring. Neurobyte's free Secure AI Deployment Checklist turns the technical controls into a self-assessment with a prioritised gap plan.

Can prompt injection be fully prevented?

Not with current models. Filters and careful system prompts reduce it, but a model cannot reliably tell instructions from data. The practical goal is to make a successful injection harmless by limiting what the model can access and do, and by requiring human approval for consequential actions.

Is it safe to send company data to ChatGPT or other public AI tools?

It depends on the tool's terms, your settings and the data. Consumer versions may retain or train on what you enter; business and API offerings usually do not by default. Set an acceptable use policy, use business-grade agreements, and never put personal data, credentials or confidential information into a tool you have not assessed.

Do we need a DPIA for an AI system in Kenya?

Often, yes. The Kenya Data Protection Act requires a data protection impact assessment where processing is likely to result in high risk, and applying new technology such as AI to personal data, especially for automated decisions with significant effects, is a typical trigger.

Does a normal penetration test cover AI features?

Only if it is scoped to. Standard web application testing checks the surrounding application but usually not model behaviour. Ask specifically for prompt injection, data leakage, retrieval bypass and agent abuse testing.