Skip to main content
MediumAI code

How to fix: User Input Concatenated Directly Into an LLM Prompt

Request-derived data is interpolated directly into an LLM API call's prompt/message content with no visible isolation or sanitization.

Why it matters

An attacker can craft input that overrides the intended system instructions (prompt injection), potentially exfiltrating other users' data, bypassing content policies, or making the model take unintended actions if it has tool access.

AI-scaffolded backends commonly template the user's message straight into the prompt string sent to the model. Without structural separation between trusted instructions and untrusted user content, the model has no reliable way to distinguish 'developer instruction' from 'attacker-supplied text masquerading as an instruction'.

How to fix it

  1. 1Keep user input in its own message role (e.g. the 'user' role) separate from the system prompt, rather than string-templating it into instructions.
  2. 2Treat any tool/function-calling output as untrusted and validate before acting on it.
  3. 3Apply an output-side check before taking irreversible actions based on model output derived from user text.

Code examples

Keep user content in its own message role

TypeScript
const response = await client.messages.create({
  system: 'You are a support assistant. Only answer questions about billing.',
  messages: [{ role: 'user', content: userInput }],
});
// Do not template userInput into the system prompt string

References

Detected automatically by VulnRadar. The check id is vibe-prompt-injection-risk, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is User Input Concatenated Directly Into an LLM Prompt?
VulnRadar rates this medium severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-prompt-injection-risk, which stays the same between runs so you can filter, diff, or gate CI on it.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for user input concatenated directly into an llm prompt

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

User Input Concatenated Directly Into an LLM Prompt | VulnRadar