Table of Contents
Generative AI has moved rapidly from experimentation into enterprise applications. Organizations are using Large Language Models (LLMs) to summarize documents, answer questions over internal knowledge, automate workflows, generate code, and support customer and employee experiences.
As these applications become more capable, the security boundary becomes more complex. A production AI application is no longer simply User → Application → LLM → Response. It may include identity providers, file uploads, retrieval pipelines, vector databases, external APIs, agent tools, memory, model endpoints, observability systems, and multiple third-party components.
That changes how enterprises need to think about AI security. The model is only one component. The real security problem is the system surrounding it: what data reaches the model, what the model can access, what its output can trigger, and whether sensitive information remains protected throughout the lifecycle.
Generative AI security should be approached as a broader lifecycle risk-management problem, with attention to the application-level risks introduced by LLM-based systems.
Understanding the Modern AI Security Attack Surface
A production AI application can expose attack surfaces through users, prompts and context, uploaded files, RAG pipelines, vector stores, model inference, agent tools, memory, secrets, logs, dependencies, and cloud infrastructure.
A production AI application can expose attack surfaces through users, prompts and context, uploaded files, RAG pipelines, vector stores, model inference, agent tools, memory, secrets, logs, dependencies, and cloud infrastructure.

Figure 1. Modern LLM applications expose multiple interconnected security boundaries.
A useful way to assess each component is to ask:
- Who can send data here?
- Who can modify the data?
- What does this component trust?
- What can it access?
- What can it cause downstream?
- How is misuse detected?
- What limits the blast radius?
The important architectural shift is to stop treating the LLM as the only security boundary. Security controls need to surround the model and the data flows that feed and consume it.
Part I – What are the Key AI Security Threats
1. Prompt Injection: When Instructions Become an Attack Vector
Prompt injection occurs when attacker-controlled instructions influence an LLM’s behavior or output in ways the application did not intend. The attack can be direct, through a user prompt, or indirect, through content the model is asked to process such as documents, web pages, emails, or other retrieved data.
Indirect prompt injection is especially important in enterprise systems because the malicious instruction may be embedded in otherwise trusted business content. A defense-in-depth approach should combine prompt analysis, content isolation, policy enforcement, least privilege, monitoring, and tool-chain controls rather than relying on a single prompt filter.
The core lesson is simple: content supplied to the model should not automatically become trusted instructions. Treat user content, retrieved content, uploaded files, and external data as untrusted inputs.
2. Sensitive Data Exposure and PII Leakage
Sensitive information can appear in prompts, retrieved context, tool calls, model responses, memory, traces, and logs.
A practical enterprise principle is to send the minimum information required for the task. Data minimization reduces the amount of sensitive information that can be exposed when another control fails.
For workloads that require the model to reason about business content without requiring the original identifiers, an application can introduce a PII protection gateway before inference.
3. RAG: The Retrieval Layer Can Become the Security Boundary
Retrieval-Augmented Generation (RAG) adds another security boundary because the application decides which enterprise information enters the model context. If retrieval is not authorization-aware, a model may receive information the requesting user should never have been able to access.
Security must therefore be enforced before retrieved content reaches the model. Key RAG risks include unauthorized access, data exfiltration, poisoning, sensitive-information disclosure, and gaps in data provenance.
- Authorization-aware retrieval
- Tenant isolation
- Document-level access controls
- Trusted ingestion and content scanning
- Data provenance
- Poisoning protection
- Grounding and output validation
The model should not be the authorization layer. Authorization belongs in the application and security layer.
4. AI Agents: From Model Risk to Action Risk
In multi-agent systems, one agent may pass instructions, data, tool results, or recommendations to another agent. The receiving agent should treat instructions received from another agent with the same caution as instructions received from a user; being generated by an internal agent does not make them trusted. A compromised or manipulated agent can become an indirect prompt-injection source for downstream agents.
Each agent-to-agent boundary should therefore be treated as a trust boundary. Data should be authenticated and validated, permissions should be evaluated independently for the receiving agent, and high-impact actions should remain subject to deterministic authorization and, where appropriate, human approval.
The principle is simple: trust should not automatically propagate across the agent chain.
5. Model Outputs Are Also Untrusted
Security controls should not stop at the input boundary. Model outputs can contain sensitive information, unsafe parameters, unexpected instructions, code, SQL, URLs, or tool arguments. Insufficient validation and sanitization can become a security problem when model output is passed directly to downstream systems.
- Schema validation
- DLP and PII checks
- Sanitization
- Business-rule validation
- Tool-parameter validation
- No direct execution of model output
A useful mental model is: model output is another form of untrusted input. It must pass through the same kind of validation and authorization boundaries applied to other externally influenced data.
6. Model, Memory, Secrets, 6.1 AI Logging and Observability Security Logging and Supply-Chain Risks
Not every AI security failure happens at an inference time. System prompts, agent memory, API keys, model artifacts, evaluation datasets, embeddings, dependencies, plugins, and logs can all become security targets.
Logs deserve particular attention because AI applications can record prompts, retrieved context, responses, tool parameters, identifiers, and error details. Logging should therefore be treated as a sensitive data store rather than an automatically safe operational system.
6.1 AI Logging and Observability Security
AI observability can itself become a data-exposure path. Prompts, retrieved context, model responses, tool parameters, identifiers, and errors may contain sensitive information. Logging should therefore apply data minimization and redaction before sensitive content enters the logging pipeline. Logs should have defined retention periods, restricted access, encryption, and monitoring for unauthorized access.
The goal is not to log everything. It is to retain enough information to investigate security events without creating a second copy of the sensitive data the application is trying to protect.
- Redact PII, secrets, and other sensitive values before logging.
- Minimize prompt and retrieved-context logging to what is necessary for debugging or audit.
- Define retention and deletion periods for AI logs and traces.
- Restrict log access through role-based access control and least privilege.
- Protect log collectors, pipelines, sinks, and integrations in transit and at rest.
- Monitor access to logs and unusual export or retrieval patterns.
Other important risks include supply-chain vulnerabilities, data and model poisoning, system prompt leakage, vector and embedding weaknesses, and unbounded consumption.
These risks reinforce a broader point: AI security has to cover the full application lifecycle, not only the inference request.
7. Model and Inference Confidentiality
Traditional controls protect data in transit and at rest. Some sensitive workloads also require stronger protection for data while it is being processed by inference infrastructure.
This is where confidential computing and cryptographic approaches such as Trusted Execution Environments (TEE) and Fully Homomorphic Encryption (FHE) become relevant. They address a different question from prompt injection or authorization: who can observe the data while computation is taking place?
8. Identity and Authorization
Start with the same principle used in traditional enterprise security: establish who is making the request and what that identity is allowed to access.
- Authenticate users and services
- Apply RBAC or ABAC where appropriate
- Enforce tenant isolation
- Use least-privilege service identities
- Separate read and write capabilities
- Use short-lived credentials for agent actions
- Do not delegate authorization decisions to the LLM
The LLM may recommend an action, but an application policy engine or deterministic authorization layer should decide whether that action is permitted.
9. Protecting Sensitive Data Before Inference
A practical PII protection pattern is to detect sensitive information before the LLM invocation, replace identified values with controlled tokens or pseudonyms, retain the original values in a protected mapping mechanism, and selectively restore them only after output validation.
This pattern is vendor-neutral. PII detection can be implemented with managed cloud services, enterprise DLP platforms, open-source detectors, custom NER models, regular expressions, deterministic rules, or combinations of these approaches. Tokenization and pseudonymization can be used to replace identifiable values with controlled representations, while masking and tokenization can reduce exposure of sensitive data in GenAI workflows.

Figure 2. A vendor-neutral PII protection pattern: detect, tokenize/pseudonymize, process, validate, and selectively restore.
PII detection should not be treated as perfect. For hard business rules, deterministic patterns and policies should provide the enforcement boundary, with probabilistic detectors used as an additional layer.
10. Secure RAG
RAG security starts before generation. The retrieval service should enforce the user’s authorization against the data source, not rely on the model to decide whether retrieved content is appropriate.
- Apply authorization-aware retrieval
- Filter by tenant and document permissions
- Classify sensitive sources
- Validate and scan content before indexing
- Track provenance and source identity
- Protect embeddings and vector stores
- Test for prompt injection and retrieval poisoning
- Validate the generated answer before release
This creates a clear separation of responsibilities: retrieval determines what information may enter the context; the model reasons over that authorized context; downstream controls validate what leaves the system.
11. Secure AI Agents and Tool Execution
Agent security should treat every tool as a privileged capability. The agent should receive only the tools and permissions required for the task, and every tool invocation should pass through an authorization and validation layer.
- Allowlist tools rather than exposing arbitrary functions
- Authorize each tool call in application policy
- Validate parameters and business constraints
- Limit transaction value, frequency, and scope
- Use short-lived credentials
- Restrict the number of steps and execution time
- Require human approval for high-impact operations
- Log and monitor tool usage
The goal is not to make an agent incapable of acting. The goal is to make every action bounded, attributable, and reversible where possible.
12. Validate Model Outputs Before Downstream Use
Every model output should be treated as untrusted data until it has passed the controls required for its destination.
- Validate against an expected schema
- Sanitize content for the receiving system
- Check for sensitive information
- Apply business rules
- Re-authorize actions before execution
- Validate tool parameters independently
- Prevent direct execution of arbitrary generated code or commands
This is especially important when model output becomes executable input for another system. Improper output handling can turn model-generated content into application-layer vulnerabilities.
13. Confidential AI: TEE and FHE

Figure 3. TEE and FHE use different confidentiality models for protected inference.
TEE and FHE address confidentiality during computation, but they use different trust models.
13.1 Trusted Execution Environments (TEE)
A Trusted Execution Environment provides a hardware-isolated execution boundary where authorized code can process protected data. A TEE provides a segregated execution environment protected from the surrounding infrastructure; code inside the TEE can process data in plaintext within that protected boundary.
TEE-based confidential AI can therefore reduce exposure to the surrounding infrastructure while allowing conventional computation. Depending on the platform, remote attestation can also help a relying party verify the environment before releasing sensitive data or keys.
TEE is particularly useful when an organization wants stronger protection for data-in-use without changing the underlying model computation to operate on ciphertext.
13.2 Fully Homomorphic Encryption (FHE)
Fully Homomorphic Encryption enables supported computation directly on encrypted data without first decrypting it. In an inference workflow, the client encrypts the query, the inference service evaluates the model over ciphertext, and the client decrypts the encrypted result.
With a TEE, queries can be decrypted and processed inside an isolated environment; with FHE, the query can remain encrypted during supported computation.
FHE provides strong cryptographic confidentiality, but the computational overhead currently makes it impractical as a general-purpose solution for large-scale LLM inference. It is an emerging approach worth watching for specialized privacy-sensitive workloads.
TEE is the more practical confidential-computing option today for many inference workloads. It protects data while it is being processed while allowing conventional model execution inside an isolated hardware-backed environment.
14. Tokenization vs Trusted Execution Environment (TEE) vs Fully Homomorphic Encryption (FHE)
These approaches solve different problems and can be layered rather than treated as competing alternatives.

For example, an enterprise could tokenize PII at the application boundary, use authorization-aware RAG, execute inference in a confidential environment, and still apply output validation and agent authorization afterward.
15. How the Security Layers Work Together
No single security control can make an AI application secure. Prompt filters can miss attacks. PII detectors can miss entities. Authorization can be misconfigured. Models can produce unexpected output. Agents can combine individually harmless tools into dangerous sequences.
A layered architecture therefore looks like:
- Identity and authorization
- Data minimization and PII/DLP controls
- Prompt and context controls
- RAG authorization and provenance
- Guardrails and prompt-injection defenses
- Protected inference where required
- Output validation
- Tool authorization and deterministic execution controls
- Logging, monitoring and security testing
Defense in depth for indirect prompt injection should combine probabilistic and deterministic mitigations, least privilege, policy controls, and monitoring. This layered approach is consistent with broader AI risk-management principles.

Figure 4. Security should be layered across identity, data, prompts, retrieval, inference, outputs, and operations.
16. Enterprise AI Security Checklist
Securing an AI application requires controls across the full application lifecycle, from data and retrieval to model interaction, tool execution, logging, and monitoring. The following checklist summarizes the key controls discussed in this article.
- Treat the LLM and retrieved content as untrusted components, not authorization mechanisms.
- Minimize sensitive data sent to the model and protect PII, secrets, prompts, memory, and retrieved context.
- Enforce authorization before sensitive data reaches the model, including document-level permissions and tenant isolation in RAG.
- Give agents only the minimum tools, permissions, and autonomy required, and independently validate high-impact actions.
- Treat instructions and data received from other agents as untrusted across agent-to-agent boundaries.
- Validate and sanitize model outputs before they are used by downstream systems or tools.
- Protect AI logs and observability pipelines through redaction, minimization, retention, access control, encryption, and monitoring.
- Use deterministic security controls for hard business rules; use TEE for many conventional confidential-inference workloads and treat FHE as an emerging option for specialized workloads.
Conclusion
Enterprise AI security is not a single guardrail around an LLM. It is an architecture of boundaries around identity, data, prompts, retrieval, inference, outputs, tools, and operations.
The most useful design principle is to assume that the model can be wrong, manipulated, or exposed to malicious content—and then make sure the surrounding system still enforces the security policy.
PII tokenization can reduce unnecessary exposure of sensitive identifiers. Authorization-aware RAG can keep protected knowledge out of unauthorized contexts. Least-privilege agents can limit what an AI system can do. Output validation can prevent generated content from becoming an uncontrolled execution path. And confidential computing or FHE can provide additional protection when data-in-use confidentiality is part of the threat model.
The result is not an AI system that is magically immune to attack. It is an AI system whose failures are constrained by explicit security boundaries, deterministic controls, and limited blast radius.