feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · KeyError

Required field is missing in salary_expectations data.

Error message

Required field {e} is missing in salary_expectations data.

What it means

KeyError raised from the salary_expectations block of JobApplicationProfile.__init__: the top-level 'salary_expectations' key is absent (dict indexing), or the SalaryExpectations constructor requires a field (e.g. 'currency' or 'amount') that the nested dict lacks and its KeyError propagates here. The missing key name is embedded in the message.

Solutions

  1. Add the missing key named in the message (top-level key or nested field).
  2. Default the section if optional: data.setdefault('salary_expectations', {}) before construction.
  3. Inspect SalaryExpectations.__init__ to see mandatory fields and fill them from source data.

Example fix

# before
self.salary_expectations = SalaryExpectations(**data['salary_expectations'])

# after
se = data.get('salary_expectations') or {}
self.salary_expectations = SalaryExpectations(**se)
Defensive patterns

Strategy: validation

Validate before calling

data.setdefault('salary_expectations', {})

Type guard

def has_salary_expectations(data: dict) -> bool:
    return isinstance(data.get('salary_expectations'), dict)

Try / catch

try:
    profile = JobApplicationProfile(**data)
except KeyError as e:
    if 'salary_expectations' in str(e):
        data.setdefault('salary_expectations', {})
        profile = JobApplicationProfile(**data)

Prevention

When it happens

Trigger: JobApplicationProfile(**data) with no 'salary_expectations' in data, or a salary dict missing a field SalaryExpectations declares as required.

Common situations: Candidates omitting salary expectations from resumes; pipelines dropping empty sections; schema changes promoting optional salary fields to required.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/resume_schemas/job_application_profile.py:161

            raise KeyError(f"Required field {e} is missing in availability data.") from e
        except TypeError as e:
            logger.error(f"Error in availability data: {e}")
            raise TypeError(f"Error in availability data: {e}") from e
        except AttributeError as e:
            logger.error(f"Attribute error in availability processing: {e}")
            raise AttributeError("Attribute error in availability processing.") from e
        except Exception as e:
            logger.error(f"An unexpected error occurred while processing availability: {e}")
            raise RuntimeError("An unexpected error occurred while processing availability.") from e

        # Process salary_expectations
        try:
            logger.debug("Processing salary_expectations")
            self.salary_expectations = SalaryExpectations(**data['salary_expectations'])
            logger.debug(f"salary_expectations processed: {self.salary_expectations}")
        except KeyError as e:
            logger.error(f"Required field {e} is missing in salary_expectations data.")
            raise KeyError(f"Required field {e} is missing in salary_expectations data.") from e
        except TypeError as e:
            logger.error(f"Error in salary_expectations data: {e}")
            raise TypeError(f"Error in salary_expectations data: {e}") from e
        except AttributeError as e:
            logger.error(f"Attribute error in salary_expectations processing: {e}")
            raise AttributeError("Attribute error in salary_expectations processing.") from e
        except Exception as e:
            logger.error(f"An unexpected error occurred while processing salary_expectations: {e}")
            raise RuntimeError("An unexpected error occurred while processing salary_expectations.") from e

        logger.debug("JobApplicationProfile initialization completed successfully.")

    def __str__(self):
        logger.debug("Generating string representation of JobApplicationProfile")

        def format_dataclass(obj):
            return "\n".join(f"{field.name}: {getattr(obj, field.name)}" for field in obj.__dataclass_fields__.values())

View on GitHub (pinned to 79155b52fa)