{"record":{"id":"130022c7fa4f9d81","repo":"rohitg00/ai-engineering-from-scratch","slug":"malformed-line-line-r","errorCode":null,"errorMessage":"malformed line: {line!r}","messagePattern":"malformed line: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/86-constitutional-rules-engine/code/yaml_subset.py","lineNumber":120,"sourceCode":"\n\ndef _parse_mapping(lines: list[str], start: int, indent: int) -> tuple[dict[str, Any], int]:\n    out: dict[str, Any] = {}\n    i = start\n    while i < len(lines):\n        line = lines[i]\n        cur_indent = _indent_of(line)\n        if cur_indent < indent:\n            break\n        if cur_indent > indent:\n            i += 1\n            continue\n        stripped = line.lstrip()\n        if stripped.startswith(\"- \"):\n            break\n        m = re.match(r\"^([A-Za-z_][\\w-]*)\\s*:\\s*(.*)$\", stripped)\n        if not m:\n            raise ValueError(f\"malformed line: {line!r}\")\n        key = m.group(1)\n        rest = m.group(2)\n        if rest.strip() == \"\":\n            if i + 1 < len(lines) and _indent_of(lines[i + 1]) > indent:\n                value, i = _parse_block(lines, i + 1, _indent_of(lines[i + 1]))\n                out[key] = value\n                continue\n            out[key] = None\n            i += 1\n        else:\n            out[key] = _coerce(rest)\n            i += 1\n    return out, i\n\n\ndef _parse_sequence(lines: list[str], start: int, indent: int) -> tuple[list[Any], int]:\n    out: list[Any] = []\n    i = start","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/86-constitutional-rules-engine/code/yaml_subset.py#L102-L138","documentation":"_parse_mapping is a hand-rolled YAML subset parser that accepts 'key: value' lines at a consistent indent; any line that is not a list item or a well-formed key-value pair at the expected indent falls through to the generic guard, meaning the YAML uses syntax outside the supported subset (flow maps, anchors, tags, or stray text).","triggerScenarios":"Thrown at phases/19-capstone-projects/86-constitutional-rules-engine/code/yaml_subset.py:120 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite the offending line as plain 'key: value' block syntax","Avoid flow style ({...}), anchors (&, *), and multi-document YAML in constitutions processed by this parser","Switch the loader to a full YAML library if the document legitimately needs richer syntax"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}