liveBook · Manning

Context-aware filtering

As explained in LLMs in Production

Context-aware filtering evaluates input or output in its surrounding semantic context to detect unsafe, unauthorized, or policy-violating content.

An email-handling LLM might follow a malicious message that asks it to write malware and send it to other contacts. Context-aware filtering checks prompts and generated outputs for unsafe requests, unauthorized actions, or sensitive data leakage. section 6.3.6

A practical filtering strategy combines several defenses:

  • Search for dangerous keywords or use a second LLM to validate inputs and outputs. section 6.3.6
  • Sanitize and validate incoming text, monitor for bypasses, and update models regularly. section 6.3.6
  • Support language-specific safeguards; denying unsupported languages improves containment but reduces usability. section 6.3.6

A layered defense

A system can reject a suspicious prompt, inspect the response for leaked secrets such as a confidential recipe, and rely on monitoring when an attacker evades both checks. A trained model may additionally refuse with “Sorry, but I can’t assist with that.” section 6.3.6

How LLMs in Production covers it

How deep it goes
Explains input/output validation, monitoring, sanitization, language checks, and model updates, but warns filtering can be bypassed.
Examples
Uses malicious email instructions, malware generation, confidential-recipe leakage, multilingual bypasses, and GPT-4 refusal behavior.
What it assumes
Assumes familiarity with prompt injection and teaches filtering as a layered response to that threat.
What you can do after
Apply it via keyword search or a second LLM, then monitor, sanitize, validate, and update defenses.
How it connects
Connects prompt injection with sanitization, validation, monitoring, language detection, and model training.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.