The Integrity Loop
Difficulty: HARDID: ai-integrity-loop
The Scenario
Your startup uses Reasoning AI for user onboarding. The LLM output is structurally perfect JSON, but semantically "jagged."
User: "I'm a time traveler from 1850, my email is secret!" LLM Output:
{"name": "Time Traveler", "age": 175, "email": "secret"}
Modern LLMs guarantee valid JSON syntax, but they still produce semantic garbage (age=175, email without @).
The Goal
Implement a Self-Healing Validator:
- Validate: Age must be 0-120; Email must contain "@".
- Retry Logic: If validation fails, call
mock_llm.generate(prompt, error_msg)exactly once more with the error details. - Final Result: Return the corrected object or raise an error if the second attempt also fails.
Requirements:
- Use a class-based validator with
validate_semantics()method. - Catch the
ValueErrorand trigger the retry. - Do not retry more than once (token efficiency).
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