feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · KeyError

Required field {e} is missing in legal_authorization data.

Error message

Required field {e} is missing in legal_authorization data.

What it means

Raised when constructing JobApplicationProfile and the LegalAuthorization section (or the data dict itself) is missing a required key. data['legal_authorization'] uses dict indexing, and LegalAuthorization(**...) requires certain fields; either KeyError source lands in this handler. The missing key name is embedded in the message via {e}.

Source

Thrown at src/resume_schemas/job_application_profile.py:107

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

        # Process legal_authorization
        try:
            logger.debug("Processing legal_authorization")
            self.legal_authorization = LegalAuthorization(**data['legal_authorization'])
            logger.debug(f"legal_authorization processed: {self.legal_authorization}")
        except KeyError as e:
            logger.error(f"Required field {e} is missing in legal_authorization data.")
            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

View on GitHub (pinned to 79155b52fa)

Solutions

  1. Add the missing key shown in the message to data (e.g. data['legal_authorization'] = {...}) or to the nested dict.
  2. Use data.setdefault('legal_authorization', {}) (or .get with a default) before construction if the section is optional.
  3. Check LegalAuthorization's __init__ signature for which fields are mandatory and supply them.

Example fix

# before
self.legal_authorization = LegalAuthorization(**data['legal_authorization'])

# after
from_legal = data.get('legal_authorization') or {}
self.legal_authorization = LegalAuthorization(**from_legal)
Defensive patterns

Strategy: validation

Validate before calling

data.setdefault('legal_authorization', {})
la = data['legal_authorization']
missing = [k for k in REQUIRED_LA_KEYS if k not in la]
assert not missing, f'missing: {missing}'

Type guard

def has_legal_authorization(data: dict) -> bool:
    return isinstance(data.get('legal_authorization'), dict)

Try / catch

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

Prevention

When it happens

Trigger: Calling JobApplicationProfile(**data) with no 'legal_authorization' key in data, or a legal_authorization dict missing a field LegalAuthorization requires (its own constructor re-raises KeyError).

Common situations: Resume YAML/JSON files that omit the legal authorization section; optional sections treated as required; pipelines that strip empty sections before construction.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — 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/2de065cb17d22b72. Report an issue: GitHub.