Teams should treat the template source as untrusted and block it from reaching the inference path until it is reviewed, signed, and normalised. The first controls are template allowlisting, input sanitisation, least-privilege execution, and separating rendering from runtime evaluation so injected instructions cannot execute inside the model service.
Why untrusted templates should be stopped before inference execution
An inference runtime should treat an untrusted template as code-like input, not as harmless presentation data. If the template can influence rendering, prompt construction, tool calls, or downstream execution, the safest first move is to keep it out of the runtime path until it has been reviewed, signed, and normalised. That reduces the chance that injected instructions or malformed structure can change model behaviour.
The key distinction is between content that is merely displayed and content that is evaluated. If the runtime parses template directives, placeholder syntax, or embedded instructions, then the template becomes part of the control plane for the model service. In that situation, allowlisting and sanitisation are not cosmetic hardening, they are the boundary that prevents attacker-controlled material from being treated as trusted operational input.
Separation matters here as much as validation. Rendering should be isolated from runtime evaluation so the system never has to infer whether a string is meant to be data, instructions, or executable template logic. In practice, that means normalising the template into a safe representation first, then only allowing approved patterns, tokens, and transformations to reach inference.
How teams should frame the first control choices
The first control choices are about reducing blast radius before you optimise user experience or template flexibility. Least-privilege execution limits what the runtime can do if a template slips through, and a strict allowlist reduces the chance that a new template feature quietly expands the attack surface. When those two controls are missing, a single unsafe template can become a broad execution path inside the model service.
Template pipelines also need provenance discipline. If a team cannot answer where a template came from, who approved it, and whether it was altered after approval, then the template should not be treated as eligible for live inference. That is especially important when templates are reused across environments, because drift between development, staging, and production can make a previously safe pattern unsafe in the deployed runtime.
Normalisation should be done with predictable rules, not ad hoc cleanup. The goal is to remove ambiguity before the template reaches the model, so the service handles one canonical form rather than multiple equivalent forms that could bypass checks. That is what makes review results durable instead of environment-specific.
What usually goes wrong when template trust is assumed
The common failure is to treat the template as a formatting artifact while the runtime interprets it as operational input. Once that happens, an attacker can use the template layer to smuggle instructions, alter system messages, or influence how the model service selects context. The issue is not only direct code execution, it is instruction injection into a path that the system has already granted execution authority.
A second failure mode is overbroad privileges around the template processor itself. If the runtime can read secrets, call internal services, or reach sensitive retrieval sources, then a compromised template can turn a presentation bug into a wider compromise. That is why template handling should be designed as if the input is adversarial from the start, not as if trust can be inferred from the fact that the content is meant to shape an LLM response.
Risk and Threat Considerations
Untrusted templates create a direct injection and privilege-abuse path when the inference service evaluates them as part of prompt construction or rendering. The main risk is that attacker-controlled template logic can change what the model sees, what it is asked to do, or what surrounding system actions are triggered.
Failure mechanism: The runtime accepts a template that has not been normalised or constrained, then evaluates it inside a trusted service context where injected directives, unsafe placeholders, or unexpected substitutions are allowed to execute or influence inference flow.
Impact: The outcome can include instruction smuggling, data exposure, unsafe tool use, corrupted outputs, or broader compromise of the model service if the template path inherits more privilege than it should.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5 and OWASP ASVS set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | SI-10 — Input Validation | Untrusted templates require strict validation before execution or rendering. |
| AC-6 — Least Privilege | The runtime should have minimal permissions if template content is abused. | |
| SC-39 — Process Isolation | Separating rendering from evaluation reduces template-to-runtime abuse paths. | |
| Recommendation — Validate template input and reject unsafe directives before the inference path processes it. Limit the template service to the smallest set of permissions needed to render safely. Isolate template parsing from model execution so injected content cannot cross execution boundaries. | ||
| ISO/IEC 27001:2022 | A.8.9 — Configuration Management | Template allowlisting and normalisation are configuration control concerns for deployed inference systems. |
| Recommendation — Control approved template versions and normalise them before deployment. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | The issue is architectural separation of untrusted input from executable runtime logic. |
| Recommendation — Design the inference pipeline so templates cannot be evaluated as executable logic. | ||
Practitioner Guidance
What to prioritise: Put a hard gate in front of the inference path so only reviewed and approved templates can enter production execution. If the template can alter control flow, treat it as a security-relevant artifact, not a UI asset.
What to verify: Confirm that the runtime enforces a single canonical template form, rejects unexpected directives, and does not allow the rendering engine to execute logic that was not explicitly approved. Also verify that the service account running the renderer cannot access more than the minimum required resources.
Common mistake: Teams often sandbox the model but leave the template processor broad and trusted. That leaves the easiest attack path intact, because the compromise happens before the model ever gets a chance to “reason” about the input.
Practitioner takeaway: The safest first decision is to stop untrusted templates at the boundary, then prove that rendering, evaluation, and execution are separated enough that template content cannot become runtime authority.
Related resources from NHI Mgmt Group
- What should teams do in the first 24 to 72 hours after discovering a compromised AI agent runtime?
- Should organisations prioritise static testing or runtime testing first?
- How do identity teams decide whether runtime detection or posture management should come first?
- How should security teams decide which vulnerabilities need runtime blocking first?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org