LLM Security & Governance: PII, Prompt Injection, and Audit Trails in Production
LLM security and governance in production: handling PII, defending against prompt injection, and keeping audit trails — plus where observability safely fits.
LLM security and governance come down to three surfaces. Protect sensitive data: keep PII out of prompts and logs, and redact what you must capture. Defend against prompt injection: treat model output and retrieved content as untrusted, and constrain tool permissions. Keep tamper-evident audit trails of who ran what, with what input and output. Observability provides the record those controls depend on — out of band, so it never becomes a new place your data leaks.
Putting an LLM in front of real users turns a model into an attack surface and a compliance obligation at the same time. The model reads untrusted input, often has tools that can act on the world, and processes data your regulators care about, all while generating output no one reviewed. Security and governance for LLMs is the work of making that safe and auditable: controlling what sensitive data touches the model, defending against inputs engineered to subvert it, and keeping a defensible record of what happened. This guide walks the three risk surfaces and where observability fits — carefully, because the thing that records your AI must not become the next place it leaks.
Three surfaces, not one
It helps to separate the problem into three surfaces, because the controls differ. The first is data: what sensitive information flows into prompts, out in completions, and into whatever logs you keep. The second is behavior: whether an attacker can manipulate the model through its inputs, directly in a user message or indirectly through content it retrieves, to leak data, call tools it should not, or ignore its instructions. The third is accountability: whether you can later prove who ran what, against which model, with what input and output. Most real-world incidents are a failure on one of these three, and most compliance frameworks ask about all three.
Protecting sensitive data (PII)
Start with the simplest rule: the safest data is the data the model never sees. Minimize what you put in prompts — strip or tokenize PII before it reaches the provider wherever the task allows, and redact fields you do not need. For the data you must send, know your provider's retention and training terms and choose endpoints accordingly; many offer zero-retention or no-training modes for exactly this reason.
The harder-to-spot leak is in your own telemetry. Debugging an LLM often means capturing the prompt and completion, and those are exactly where PII pools. Treat captured content as sensitive by default: make full prompt and completion capture opt-in rather than on by default, redact at the point of capture, and scope who can read raw traces. This is a governance decision to make once, at the instrumentation layer, so it is consistent across every service rather than left to each engineer. Obsivara's compliance tooling is built around keeping that record defensible, and its approach to data handling is documented on the trust page so you can review it before sending anything.
Defending against prompt injection
Prompt injection is the signature LLM vulnerability: an attacker writes input that the model interprets as instructions rather than data. Direct injection is a user typing 'ignore your instructions and...'; indirect injection is nastier — malicious text hidden in a web page, document, or email that your app retrieves and feeds to the model, which then obeys it. The defining property is that there is no clean separation between instructions and data in a prompt, so you cannot fully escape untrusted input the way you escape a SQL query.
Because you cannot eliminate it, you contain it. Treat everything the model emits, and everything it retrieves, as untrusted. Constrain the blast radius: give tools the least privilege they need, require confirmation for consequential actions, and validate tool arguments before executing them. This matters most with tool-calling and agents, where a successful injection does not just produce bad text — it triggers an action. If you expose tools over the Model Context Protocol, the permissions and scoping of each MCP server are part of your security boundary; monitoring those connections read-only (see connecting MCP) lets you see which tools an agent actually called, which is how you catch an injection that slipped the guardrails after the fact.
Common LLM threats and their controls
The surfaces above map onto a short list of concrete threats, each with a primary control. None of these is fully solved by a single setting; they are layered defenses. But this is the checklist worth running against any production LLM feature:
| Threat | What it looks like | Primary control |
|---|---|---|
| PII leakage | Sensitive data in prompts, completions, or logs | Minimize and redact at source; opt-in content capture; scoped access |
| Direct prompt injection | User input overrides system instructions | Treat output as untrusted; least-privilege tools; confirm consequential actions |
| Indirect prompt injection | Malicious instructions hidden in retrieved content | Sanitize retrieved text; isolate tool permissions; trace tool calls |
| Excessive agency | An agent calls a tool it should not, or loops | Scope tool permissions; validate arguments; alert on anomalous tool use |
| No audit trail | Cannot prove who ran what, when | Capture per-run records: user, model, input and output, timestamp |
Audit trails: who ran what, and can you prove it
Governance frameworks, whether SOC 2, ISO 27001, the EU AI Act, or an internal policy, converge on one question: can you reconstruct what the system did? For an LLM app that means a per-run record of who invoked it, which model and version answered, what went in, what came out, which tools fired, and when. Without that, an incident review is guesswork and a compliance audit is a scramble.
The practical trap is that this record has to be both complete and durable, yet you built your logging for debugging, not evidence. Audit trails need to resist tampering, retain for a defined period, and be queryable by run — properties a scatter of application logs rarely has. Capturing traces in a dedicated, access-controlled system, with a retention policy you can state, turns 'we think it did X' into 'here is the run.' That is the governance half of observability: the same trace that helps you debug a failure is the record that satisfies an auditor.
Where observability fits — without becoming a new risk
There is a tension worth naming: the tool that records every prompt and completion is, by construction, a concentration of exactly the data you are trying to protect. Two design choices resolve it. First, out-of-band ingestion: your application keeps calling the provider directly and ships a copy of the telemetry asynchronously, via SDK, OTLP, webhook, or a read-only n8n connection, so the observability layer is never in your request path and never a proxy your traffic and credentials must pass through. Nothing to intercept, nothing new to fail in the hot path.
Second, data minimization in the telemetry itself: capture the metadata and metrics by default, model, token counts, latency, tool calls, status, and make raw prompt and completion text opt-in and redactable, so the record is useful without being a liability. Handled this way, observability strengthens your security posture instead of widening it: it gives you the audit trail governance demands and the tool-call visibility that catches injection, without becoming a second copy of your sensitive data sitting in the request path.
Make it a practice, not a one-off
Security and governance for LLMs are not a feature you buy once; they are controls you design in across data, behavior, and accountability, and then watch. Minimize and redact the data, assume every input and output is untrusted and constrain what your tools can do, and keep a durable per-run record you can actually produce on demand. Do that, and you can give auditors and security reviewers a straight answer instead of a shrug.
Obsivara captures that per-run record out of band, with content capture opt-in and access scoped, so it serves as both your debugging trace and your audit trail without sitting in your request path. Its data-handling practices are laid out on the trust page, and plans scale from a free tier upward as your estate and compliance needs grow (see pricing).
Frequently asked questions
How do you prevent PII from leaking into LLM prompts and logs?
Minimize first — strip or tokenize personal data before it reaches the model wherever the task allows, and redact fields you do not need. For data you must send, use provider endpoints with zero-retention or no-training terms. The often-missed leak is your own telemetry: debugging captures prompts and completions, which is where PII pools, so make full content capture opt-in, redact at the point of capture, and scope who can read raw traces rather than logging everything by default.
What is prompt injection and how do you defend against it?
Prompt injection is input crafted so the model treats it as instructions instead of data — directly in a user message, or indirectly via malicious text hidden in content the app retrieves. Because a prompt has no clean boundary between instructions and data, you cannot fully escape it, so you contain it: treat all model output and retrieved content as untrusted, give tools least privilege, validate tool arguments, and require confirmation for consequential actions. Tracing which tools an agent actually called helps you catch an injection that slipped the guardrails.
What should an LLM audit trail contain?
A per-run record that lets you reconstruct what happened: who invoked the call, which model and version answered, the input and output, which tools fired, and the timestamp. For governance frameworks like SOC 2, ISO 27001, or the EU AI Act, that record must be durable, access-controlled, retained for a defined period, and queryable by run — not scattered across application logs built for debugging. Capturing traces in a dedicated system turns a vague 'we think it did X' into 'here is the exact run.'
See your AI operations clearly.
Connect your stack in minutes — Obsivara discovers every workflow, scores its health, and attributes every dollar.