feder-cr/Jobs_Applier_AI_Agent_AIHawk · error · TypeError

YAML data must be a dictionary.

Error message

YAML data must be a dictionary.

What it means

After successful YAML parsing, the constructor requires the top-level document to be a mapping (dict). If safe_load produced a list, string, number, or None (empty input), a TypeError('YAML data must be a dictionary.') is raised because key-based access like data['self_identification'] would fail.

Source

Thrown at src/resume_schemas/job_application_profile.py:80

    work_preferences: WorkPreferences
    availability: Availability
    salary_expectations: SalaryExpectations

    def __init__(self, yaml_str: str):
        logger.debug("Initializing JobApplicationProfile with provided YAML string")
        try:
            data = yaml.safe_load(yaml_str)
            logger.debug(f"YAML data successfully parsed: {data}")
        except yaml.YAMLError as e:
            logger.error(f"Error parsing YAML file: {e}")
            raise ValueError("Error parsing YAML file.") from e
        except Exception as e:
            logger.error(f"Unexpected error occurred while parsing the YAML file: {e}")
            raise RuntimeError("An unexpected error occurred while parsing the YAML file.") from e

        if not isinstance(data, dict):
            logger.error(f"YAML data must be a dictionary, received: {type(data)}")
            raise TypeError("YAML data must be a dictionary.")

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

View on GitHub (pinned to 79155b52fa)

Solutions

  1. Ensure the YAML root is a mapping: top-level keys like self_identification, personal_info etc. with nested values, not a top-level list.
  2. Check for an accidentally empty file or one containing only comments.
  3. If you meant to load a list document, wrap it in a dict key first.

Example fix

# before
# resume.yaml
- self_identification: ...
# after
# resume.yaml
self_identification:
  ...  # root must be a mapping
Defensive patterns

Strategy: type-guard

Validate before calling

import yaml
data = yaml.safe_load(text)
assert isinstance(data, dict), f'YAML root must be a mapping, got {type(data).__name__}'

Type guard

def yaml_root_is_mapping(text: str) -> bool:
    import yaml
    return isinstance(yaml.safe_load(text), dict)

Try / catch

try:
    profile = JobApplicationProfile(text)
except TypeError as e:
    if 'must be a dictionary' in str(e):
        raise ConfigError('resume.yaml root must be a mapping') from e
    raise

Prevention

When it happens

Trigger: YAML whose root is a sequence ('- item' lines) or a plain scalar, or an empty/None document (empty file, or content that is only comments).

Common situations: YAML file containing only a list of jobs, a file of comments after cleanup, or passing the wrong file entirely (e.g. a plain text file).

Related errors


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