The Hallucination Trap
Difficulty: HARDID: ai-json-guard-003
The Scenario
You are building a user registration bot. The LLM extracts user details from natural language.
User: "I'm 200 years old and my email is 'nope'." LLM Output:
{"name": "Unknown", "age": 200, "email": "nope"}
This JSON is syntactically valid but semantically garbage.
- Age 200 is impossible.
- Email "nope" is invalid.
The Goal
Implement a Validator Class (simulating Pydantic):
- Define a
Userclass with validation logic. agemust be between 0 and 120.emailmust contain "@".- If validation fails, raise
ValueError.
Requirements:
- Parse the JSON.
- Instantiate
User(name, age, email). - The
__init__method must validate the fields. - Raise
ValueErrorif invalid.
solution.py
Loading...
⚠️ Do not include PII or secrets in your code.
SYSTEM_LOGS
5/5
// Waiting for execution trigger...
PREVIEW MODE — SOLVE PREVIOUS MISSIONS TO UNLOCK