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):

  1. Define a User class with validation logic.
  2. age must be between 0 and 120.
  3. email must contain "@".
  4. If validation fails, raise ValueError.

Requirements:

  • Parse the JSON.
  • Instantiate User(name, age, email).
  • The __init__ method must validate the fields.
  • Raise ValueError if 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