feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · ValueError
Chain not defined for section '{section_name}'
Error message
Chain not defined for section '{section_name}' What it means
Even when the section exists in the data, answer_question_textual_wide_range needs an LCEL chain per section (chains.get(section_name)) to answer the question. If the dict has no chain registered under the extracted name, a ValueError is raised because there is no way to generate an answer.
Source
Thrown at src/libs/llm_manager.py:602
}
)
output = self._clean_llm_output(raw_output)
logger.debug(f"Cover letter generated: {output}")
return output
resume_section = getattr(self.resume, section_name, None) or getattr(
self.job_application_profile, section_name, None
)
if resume_section is None:
logger.error(
f"Section '{section_name}' not found in either resume or job_application_profile."
)
raise ValueError(
f"Section '{section_name}' not found in either resume or job_application_profile."
)
chain = chains.get(section_name)
if chain is None:
logger.error(f"Chain not defined for section '{section_name}'")
raise ValueError(f"Chain not defined for section '{section_name}'")
raw_output = chain.invoke(
{RESUME_SECTION: resume_section, QUESTION: question}
)
output = self._clean_llm_output(raw_output)
logger.debug(f"Question answered: {output}")
return output
def answer_question_numeric(
self, question: str, default_experience: str = 3
) -> str:
logger.debug(f"Answering numeric question: {question}")
func_template = self._preprocess_template_string(
prompts.numeric_question_template
)
prompt = ChatPromptTemplate.from_template(func_template)
chain = prompt | self.llm_cheap | StrOutputParser()
raw_output_str = chain.invoke(
{View on GitHub (pinned to 79155b52fa)
Solutions
- Register a chain for every section name the regex can produce: the keys of chains must cover personal_info, skills, education, experience_details, projects, availability, salary_expectations, certifications, languages, interests, cover_letter.
- Check for normalization mismatches: extracted names are lowercased with spaces replaced by underscores; align chain keys to that convention.
- If a section intentionally has no chain, catch the ValueError and fall back to a generic QA chain.
Example fix
# before
chains = {'skills': skills_chain}
# after
chains = {
'skills': skills_chain,
'education': education_chain,
'experience_details': experience_chain,
'certifications': certifications_chain,
# ... one entry per recognized section
} Defensive patterns
Strategy: validation
Validate before calling
REQUIRED_CHAINS = {'personal_info','skills','education','experience_details','projects','availability','salary_expectations','certifications','languages','interests','cover_letter'}
assert REQUIRED_CHAINS <= set(chains), f'missing chains: {REQUIRED_CHAINS - set(chains)}' Type guard
def chains_complete(chains: dict) -> bool:
REQUIRED = {'personal_info','skills','education','experience_details','projects','availability','salary_expectations','certifications','languages','interests','cover_letter'}
return REQUIRED.issubset(chains.keys()) Try / catch
try:
ans = llm_manager.answer_question_textual_wide_range(q)
except ValueError as e:
if 'Chain not defined' in str(e):
ans = generic_chain.invoke({'resume_section': '', 'question': q})
else:
raise Prevention
- Keep the chains registry in one place with an assertion that it covers every recognized section.
- After renaming a chain key, grep the section-name normalization (lower + underscore) to stay consistent.
When it happens
Trigger: The extracted section name (from the LLM reply, lowercased and underscored) has no matching key in the chains mapping, e.g. chains was built for a subset of sections, or a section name normalization mismatch ('salary_expectations' vs 'salary').
Common situations: Customizing the chains dict without adding entries for all regex-recognized sections, renaming chain keys during refactoring, or schema changes introducing new sections.
Related errors
- Unsupported model type: {llm_model_type}
- Could not extract section name from the response.
- Section '{section_name}' not found in either resume or job_a
- No numbers found in the string
- Failed to get a response from the model after multiple attem
AI-assisted analysis of feder-cr/Jobs_Applier_AI_Agent_AIHawk@79155b52fa (2026-08-28).
Data as JSON: /api/errors/8e30b021d967280c.
Report an issue: GitHub.