Write classify_failure(trace) that returns one of
"retrieval", "prompt", "hallucination", or "parse".
Apply the priority order from the chapter:
- If
trace["retrieved_chunks"]is non-empty ANDtrace["retrieved_chunks_match_query"]isFalse→"retrieval". - Else if
trace["raw_output"] != trace["output_after_postprocess"]→"parse". - Else if
trace["retrieved_chunks"]is empty (the list[]) →"hallucination". - Else →
"prompt".
Three traces run for you, one per branch. Expected output:
retrieval
parse
hallucination