feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · KeyError

Required field is missing in work_preferences data.

Error message

Required field {e} is missing in work_preferences data.

What it means

KeyError raised from the work_preferences block of JobApplicationProfile.__init__: either 'work_preferences' itself is absent from data (dict indexing data['work_preferences']), or the WorkPreferences constructor is missing a required key and its own KeyError propagates here. The missing key name appears in the interpolated message.

Solutions

  1. Supply the missing key named in the message, at the top level or inside work_preferences.
  2. Default the section if optional: data.setdefault('work_preferences', {}) before construction.
  3. Check WorkPreferences.__init__ for required fields and pre-fill them from the source data.

Example fix

# before
self.work_preferences = WorkPreferences(**data['work_preferences'])

# after
wp = data.get('work_preferences') or {}
self.work_preferences = WorkPreferences(**wp)
Defensive patterns

Strategy: validation

Validate before calling

data.setdefault('work_preferences', {})

Type guard

def has_work_preferences(data: dict) -> bool:
    return isinstance(data.get('work_preferences'), dict)

Try / catch

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

Prevention

When it happens

Trigger: JobApplicationProfile(**data) called with a resume dict lacking 'work_preferences', or with a work_preferences mapping missing a field WorkProfiles requires (e.g. 'remote').

Common situations: Resume files that omit optional-feeling sections like work preferences; data pipelines trimming empty dicts; schema evolution adding new required keys.

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/934d7d807154e0e2. Report an issue: GitHub.

Appendix: source

Thrown at src/resume_schemas/job_application_profile.py:125

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

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

        # Process availability
        try:
            logger.debug("Processing availability")
            self.availability = Availability(**data['availability'])
            logger.debug(f"Availability processed: {self.availability}")
        except KeyError as e:
            logger.error(f"Required field {e} is missing in availability data.")
            raise KeyError(f"Required field {e} is missing in availability data.") from e

View on GitHub (pinned to 79155b52fa)