Skip to content
Guest
AI Engineering · Course Syllabus Show lessons
Safety & Evals · 10 min read · Intermediate

Prompt Injection Defense & Safety Guardrails

Protect AI apps against prompt injection, data exfiltration, and unauthorized tool actions using least privilege.

What you'll learn

  • Treat all user text and retrieved web/PDF chunks as untrusted data
  • Enforce row-level authorization in tool handlers (never trust the LLM to filter tenant IDs)
  • Require human confirmation before destructive tool calls (delete, payment, email)

Overview

Protect AI apps against prompt injection, data exfiltration, and unauthorized tool actions using least privilege.

Code Example

// Always enforce auth on the server, never via prompt text alone
async function deleteRecord(userId: string, recordId: string) {
  return db.query('DELETE FROM items WHERE id = $1 AND owner_id = $2', [recordId, userId]);
}

Key Takeaways

  • Treat all user text and retrieved web/PDF chunks as untrusted data
  • Enforce row-level authorization in tool handlers (never trust the LLM to filter tenant IDs)
  • Require human confirmation before destructive tool calls (delete, payment, email)

Quick Check

Check Your Understanding

Score: 0 / 1

1. Why is telling an LLM 'Never show other users' data' in the system prompt NOT sufficient security?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind