feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · KeyError

Missing field in experience details: {e}

Error message

Missing field in experience details: {e}

What it means

A required key is missing from an experience entry — ExperienceDetails construction uses direct indexing exp['industry'] (and similar) while optional fields use .get(). When the source dict lacks one of the subscripted keys, KeyError propagates and is re-raised with this message; the chained exception names the exact key.

Source

Thrown at src/resume_schemas/resume.py:180

        for exp in data:
            try:
                key_responsibilities = [
                    Responsibility(description=list(resp.values())[0])
                    for resp in exp.get('key_responsibilities', [])
                ]
                skills_acquired = [str(skill) for skill in exp.get('skills_acquired', [])]
                experience = ExperienceDetails(
                    position=exp['position'],
                    company=exp['company'],
                    employment_period=exp['employment_period'],
                    location=exp['location'],
                    industry=exp['industry'],
                    key_responsibilities=key_responsibilities,
                    skills_acquired=skills_acquired
                )
                experience_list.append(experience)
            except KeyError as e:
                raise KeyError(f"Missing field in experience details: {e}") from e
            except TypeError as e:
                raise TypeError(f"Invalid data for Experience: {e}") from e
            except AttributeError as e:
                raise AttributeError(f"AttributeError in Experience: {e}") from e
            except Exception as e:
                raise Exception(f"Unexpected error in Experience processing: {e}") from e
        return experience_list


@dataclass
class Exam:
    name: str
    grade: str

@dataclass
class Responsibility:
    description: str

View on GitHub (pinned to 79155b52fa)

Solutions

  1. Read the chained KeyError for the missing key name; add it to the data or switch to exp.get('industry') if the field is optional.
  2. Pre-validate: required = {'job_title', 'company', 'industry', ...}; assert required <= exp.keys().
  3. Give the dataclass field a default (Optional[str] = None) if the data is legitimately incomplete.

Example fix

// before
experience = ExperienceDetails(industry=exp['industry'], ...)

# after
experience = ExperienceDetails(industry=exp.get('industry'), ...)  # if optional
Defensive patterns

Strategy: validation

Validate before calling

REQUIRED_EXP = {'industry'}  # keys accessed via exp[...]

def validate_experience_entry(exp: dict):
    if not isinstance(exp, dict):
        raise ValueError(f"experience entry must be dict, got {type(exp).__name__}")
    missing = REQUIRED_EXP - exp.keys()
    if missing:
        raise ValueError(f"experience entry missing: {sorted(missing)}")

Type guard

def is_experience_entry(x: Any) -> TypeGuard[dict]:
    return isinstance(x, dict)

Try / catch

try:
    exp_list = _process_experience_details(data)
except KeyError as e:
    logger.warning("experience missing %s; skipping section", e.args[0])
    exp_list = []

Prevention

When it happens

Trigger: An element of the experience list missing 'industry' or another directly-indexed required key, e.g. exp = {'job_title': 'Dev'} without 'industry'.

Common situations: Sparse experience records where candidates omit industry; LLM extraction dropping rarely-filled fields; schema versions where the field became required.

Related errors


AI-assisted analysis of feder-cr/Jobs_Applier_AI_Agent_AIHawk@79155b52fa (2026-08-28). Data as JSON: /api/errors/65036f161ca6322f. Report an issue: GitHub.