{"record":{"id":"65746c2ae15927d8","repo":"feder-cr/Jobs_Applier_AI_Agent_AIHawk","slug":"could-not-extract-section-name-from-the-response","errorCode":null,"errorMessage":"Could not extract section name from the response.","messagePattern":"Could not extract section name from the response\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/libs/llm_manager.py","lineNumber":573,"sourceCode":"            LANGUAGES: self._create_chain(prompts.languages_template),\n            INTERESTS: self._create_chain(prompts.interests_template),\n            COVER_LETTER: self._create_chain(prompts.coverletter_template),\n        }\n\n        prompt = ChatPromptTemplate.from_template(prompts.determine_section_template)\n        chain = prompt | self.llm_cheap | StrOutputParser()\n        raw_output = chain.invoke({QUESTION: question})\n        output = self._clean_llm_output(raw_output)\n\n        match = re.search(\n            r\"(Personal information|Self Identification|Legal Authorization|Work Preferences|Education \"\n            r\"Details|Experience Details|Projects|Availability|Salary \"\n            r\"Expectations|Certifications|Languages|Interests|Cover letter)\",\n            output,\n            re.IGNORECASE,\n        )\n        if not match:\n            raise ValueError(\"Could not extract section name from the response.\")\n\n        section_name = match.group(1).lower().replace(\" \", \"_\")\n\n        if section_name == \"cover_letter\":\n            chain = chains.get(section_name)\n            raw_output = chain.invoke(\n                {\n                    RESUME: self.resume,\n                    JOB_DESCRIPTION: self.job_description,\n                    COMPANY: self.job.company,\n                }\n            )\n            output = self._clean_llm_output(raw_output)\n            logger.debug(f\"Cover letter generated: {output}\")\n            return output\n        resume_section = getattr(self.resume, section_name, None) or getattr(\n            self.job_application_profile, section_name, None\n        )","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/feder-cr/Jobs_Applier_AI_Agent_AIHawk/blob/79155b52faccfbd19b834680af285eac70dd2df4/src/libs/llm_manager.py#L555-L591","documentation":"answer_question_textual_wide_range asks the LLM which resume section a question belongs to, then regex-matches the reply against a fixed list (Personal Info, Skills, Education, Experience Details, Projects, Availability, Salary Expectations, Certifications, Languages, Interests, Cover letter). If the model's free-text answer contains none of these keywords, the section cannot be determined and a ValueError is raised.","triggerScenarios":"The LLM answers a screening question with wording that does not include any of the recognized section names (hallucinated or off-script reply), or the question is about something outside the enumerated sections.","commonSituations":"Flaky/creative LLM outputs, changing to a cheaper or different model that ignores instructions, prompt template changes, or non-English model responses.","solutions":["Retry the call: non-deterministic LLM output often matches on a second attempt.","Use a more instruction-following model (or lower temperature) for this chain so the reply names a valid section.","Extend the regex alternation in the prompt/validation to cover additional section names your resumes use."],"exampleFix":"// before\nanswer = llm_manager.answer_question_textual_wide_range(q)\n// after\nfor _ in range(3):\n    try:\n        answer = llm_manager.answer_question_textual_wide_range(q)\n        break\n    except ValueError:\n        continue  # LLM reply didn't name a recognizable section","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        return llm_manager.answer_question_textual_wide_range(question)\n    except ValueError as e:\n        if 'Could not extract section' not in str(e):\n            raise\nlogger.warning('Section classification failed for: %s', question)","preventionTips":["Use an instruction-following model for the classification chain and keep temperature low.","Pre-test your model choice against the fixed section list with sample screening questions."],"tags":["python","llm","regex","parsing","non-deterministic"],"backgroundTag":"llm-output-parsing-failed","analyzedSha":"79155b52faccfbd19b834680af285eac70dd2df4","analyzedAt":"2026-08-28T14:10:26.659Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}