{"record":{"id":"2de065cb17d22b72","repo":"feder-cr/Jobs_Applier_AI_Agent_AIHawk","slug":"required-field-e-is-missing-in-legal-authorizati","errorCode":null,"errorMessage":"Required field {e} is missing in legal_authorization data.","messagePattern":"Required field (.+?) is missing in legal_authorization data\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/resume_schemas/job_application_profile.py","lineNumber":107,"sourceCode":"            raise KeyError(f\"Required field {e} is missing in self_identification data.\") from e\n        except TypeError as e:\n            logger.error(f\"Error in self_identification data: {e}\")\n            raise TypeError(f\"Error in self_identification data: {e}\") from e\n        except AttributeError as e:\n            logger.error(f\"Attribute error in self_identification processing: {e}\")\n            raise AttributeError(\"Attribute error in self_identification processing.\") from e\n        except Exception as e:\n            logger.error(f\"An unexpected error occurred while processing self_identification: {e}\")\n            raise RuntimeError(\"An unexpected error occurred while processing self_identification.\") from e\n\n        # Process legal_authorization\n        try:\n            logger.debug(\"Processing legal_authorization\")\n            self.legal_authorization = LegalAuthorization(**data['legal_authorization'])\n            logger.debug(f\"legal_authorization processed: {self.legal_authorization}\")\n        except KeyError as e:\n            logger.error(f\"Required field {e} is missing in legal_authorization data.\")\n            raise KeyError(f\"Required field {e} is missing in legal_authorization data.\") from e\n        except TypeError as e:\n            logger.error(f\"Error in legal_authorization data: {e}\")\n            raise TypeError(f\"Error in legal_authorization data: {e}\") from e\n        except AttributeError as e:\n            logger.error(f\"Attribute error in legal_authorization processing: {e}\")\n            raise AttributeError(\"Attribute error in legal_authorization processing.\") from e\n        except Exception as e:\n            logger.error(f\"An unexpected error occurred while processing legal_authorization: {e}\")\n            raise RuntimeError(\"An unexpected error occurred while processing legal_authorization.\") from e\n\n        # Process work_preferences\n        try:\n            logger.debug(\"Processing work_preferences\")\n            self.work_preferences = WorkPreferences(**data['work_preferences'])\n            logger.debug(f\"Work_preferences processed: {self.work_preferences}\")\n        except KeyError as e:\n            logger.error(f\"Required field {e} is missing in work_preferences data.\")\n            raise KeyError(f\"Required field {e} is missing in work_preferences data.\") from e","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/feder-cr/Jobs_Applier_AI_Agent_AIHawk/blob/79155b52faccfbd19b834680af285eac70dd2df4/src/resume_schemas/job_application_profile.py#L89-L125","documentation":"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}.","triggerScenarios":"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).","commonSituations":"Resume YAML/JSON files that omit the legal authorization section; optional sections treated as required; pipelines that strip empty sections before construction.","solutions":["Add the missing key shown in the message to data (e.g. data['legal_authorization'] = {...}) or to the nested dict.","Use data.setdefault('legal_authorization', {}) (or .get with a default) before construction if the section is optional.","Check LegalAuthorization's __init__ signature for which fields are mandatory and supply them."],"exampleFix":"# before\nself.legal_authorization = LegalAuthorization(**data['legal_authorization'])\n\n# after\nfrom_legal = data.get('legal_authorization') or {}\nself.legal_authorization = LegalAuthorization(**from_legal)","handlingStrategy":"validation","validationCode":"data.setdefault('legal_authorization', {})\nla = data['legal_authorization']\nmissing = [k for k in REQUIRED_LA_KEYS if k not in la]\nassert not missing, f'missing: {missing}'","typeGuard":"def has_legal_authorization(data: dict) -> bool:\n    return isinstance(data.get('legal_authorization'), dict)","tryCatchPattern":"try:\n    profile = JobApplicationProfile(**data)\nexcept KeyError as e:\n    if 'legal_authorization' in str(e):\n        data.setdefault('legal_authorization', {})\n        profile = JobApplicationProfile(**data)","preventionTips":["Use .get(section, {}) instead of data[section] for optional sections","Run yamllint/jsonschema validation on resume files before loading","Document which sections are required vs optional"],"tags":["python","keyerror","missing-field","schema-validation"],"backgroundTag":"missing-required-field","analyzedSha":"79155b52faccfbd19b834680af285eac70dd2df4","analyzedAt":"2026-08-28T14:10:26.659Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}