A failed run that just gets discarded teaches the system nothing. A cheap first step toward actually learning from it: recognize which category of failure this was, from a small, curated set of known patterns, and attach the lesson already written for that category — no model call needed, just pattern matching against categories a team has already identified and written guidance for.
You're given failed_step (the text describing what the failed step reported) and error_keywords, an ordered mapping from a substring pattern to the lesson text for that failure category. Implement extract_lesson(failed_step, error_keywords). Return the lesson for the first pattern (in error_keywords's iteration/insertion order) that appears as a substring anywhere in failed_step. If no pattern matches, return the literal string "No specific lesson identified -- investigate manually.".
error_keywords has 0 to 100 entries; matching is case-sensitive, plain substring.dict iteration in modern Python walks keys in insertion order, so a plain for pattern, lesson in error_keywords.items(): loop already checks patterns in exactly the order the problem asks for — no need to sort or otherwise reorder anything.
Return the moment the first match is found. Don't collect every matching pattern's lesson and pick one afterward — the first match in dict order is the only one that matters.
No results yet
Run your code to check it against the examples, or submit to run every test.