Monitor and enhance security measures over time to safeguard your LLM applications.
Quality and Safety for LLM Applications
Instructor: Bernease Herman
Earn an accomplishment with PRO · Updated Mar 18, 2026

- Beginner
- 2h9m
- 7 Video Lessons
- 5 Code Examples
- 1 Graded Assignment PRO
- Earn an accomplishment with PRO
- Updated Mar 18, 2026
- Instructor: Bernease Herman
WhyLabs- Learn more aboutMembership PRO Plan
What you'll learn
Detect and prevent critical security threats like hallucinations, jailbreaks, and data leakage.
Explore real-world scenarios to prepare for potential risks and vulnerabilities.
Course recap
PROThis course teaches practitioners how to detect and measure the most common ways an LLM-powered application can go wrong before and after it reaches production. Rather than relying on manual spot-checking, it builds a toolkit of quantitative metrics — some as simple as string matching, others using embeddings, entity recognition, or LLM-as-judge — to systematically catch hallucinations, data leakage, toxicity, refusals, and prompt injections in prompt/response data.
Concept map
Key concepts
- Hallucination detectionmeasuring whether an LLM response is inaccurate or irrelevant to its prompt
- Prompt response relevanceusing sentence embedding cosine similarity to flag responses unrelated to the prompt
- Self consistency checkingself-check GPT-style comparison of multiple LLM responses to the same prompt to estimate hallucination risk
- Data leakagepersonally identifiable or confidential information appearing in prompts or responses
- PII detectionregex pattern matching for emails, phone numbers, SSNs, and credit card numbers
- Named entity recognitionusing NER models to catch confidential entities (people, products, organizations) that regex misses
- Toxicity detectionexplicit vs. implicit toxicity, and models like ToxiGen/HateBERT for detecting subtle harmful content
- LLM refusalsdetecting when an LLM declines to respond, via string matching and sentiment heuristics
- Prompt injectionmalicious attempts to manipulate an LLM system beyond its designers' intent
- Jailbreaksprompt injections that use indirection (hypotheticals, role-play) to bypass refusals
- LLM observabilitypassive monitoring (post-hoc profiling) vs. active monitoring (real-time validation and intervention)
- BLEU score and BERTScoretoken-based and embedding-based text similarity metrics
Lesson highlights
- 1.Overview — Introduces the course dataset (labeled prompt/response pairs) and `whylogs`/`langkit` tooling; gives a hands-on tour of metrics for hallucinations, data leakage, toxicity, refusals, and jailbreaks, and an evaluation dashboard for tracking pass/fail against target objectives.
- 2.Hallucinations — Builds four metrics to detect hallucinations: BLEU score and BERTScore (prompt-vs-response comparison), and sentence-embedding self-similarity and LLM-judged self-similarity (response-vs-response comparison), following the self-check GPT approach.
- 3.Data Leakage — Uses regex pattern matching (`langkit`'s regexes module) to catch PII like emails, phone numbers, SSNs, and credit card numbers, then adds a SpanMarker-based named entity recognition metric to catch confidential entities regex misses; closes with a bonus section on explicit vs. implicit toxicity using ToxiGen/HateBERT.
- 4.Refusals and prompt injections — Detects refusals via string matching and sentiment heuristics, then detects jailbreaks (a type of prompt injection) via prompt length heuristics and semantic similarity against a curated list of known jailbreak phrasings, including `langkit`'s built-in injections module.
- 5.Passive and active monitoring — Shows how to register custom metrics into a production-style `whylogs` logger, apply them passively (profiling logged data over time to spot trends) and actively (validating each request/response in real time with conditions and actions, such as raising a custom exception to substitute a safe fallback response).
About this course
It’s always crucial to address and monitor safety and quality concerns in your applications. Building LLM applications poses special challenges.
In this course, you’ll explore new metrics and best practices to monitor your LLM systems and ensure safety and quality. You’ll learn how to:
- Identify hallucinations with methods like SelfCheckGPT
- Detect jailbreaks (prompts that attempt to manipulate LLM responses) using sentiment analysis and implicit toxicity detection models.
- Identify data leakage using entity recognition and vector similarity analysis.
- Build your own monitoring system to evaluate app safety and security over time.
Upon completing the course, you’ll have the ability to identify common security concerns in LLM-based applications, and be able to customize your safety and security evaluation tools to the LLM that you’re using for your application.
Who should join?
Anyone with basic Python knowledge interested in mitigating issues like hallucinations, prompt injections, and toxic outputs.
Course Outline
7 Lessons・5 Code Examples

Elevate your learning experience with Pro
Upgrade to Pro and gain unlimited accomplishments on your resume
Instructor
Course access is free for a limited time during the DeepLearning.AI learning platform beta!
Want to learn more about Generative AI?
Keep learning with updates on curated AI news, courses, and events, as well as Andrew’s thoughts from DeepLearning.AI!

