rohitg00/ai-engineering-from-scratch · error · PaperValidationError

section references unknown figure id

Error message

section {sec.id!r} references unknown figure id {fid!r}

What it means

Reference-integrity guard: a section's figure_refs list names a figure id that no Figure object defines, so the LaTeX figure reference would dangle.

Solutions

  1. Attach the referenced Figure to paper.figures
  2. Correct the figure id string in the section's figure_refs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/54-paper-writer/code/main.py:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/db530576bd222c91. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/54-paper-writer/code/main.py:101

    for fig in paper.figures:
        if fig.id in fig_ids:
            raise PaperValidationError(f"duplicate figure id: {fig.id}")
        fig_ids.add(fig.id)

    bib_keys: set[str] = set()
    for b in paper.bibliography:
        if b.key in bib_keys:
            raise PaperValidationError(f"duplicate bibliography key: {b.key}")
        bib_keys.add(b.key)
    for sec in paper.sections:
        for key in sec.cites:
            if key not in bib_keys:
                raise PaperValidationError(
                    f"section {sec.id!r} cites unknown bibliography key {key!r}"
                )
        for fid in sec.figure_refs:
            if fid not in fig_ids:
                raise PaperValidationError(
                    f"section {sec.id!r} references unknown figure id {fid!r}"
                )


def _escape_latex(text: str) -> str:
    repl = {
        "\\": r"\textbackslash{}",
        "&": r"\&",
        "%": r"\%",
        "$": r"\$",
        "#": r"\#",
        "_": r"\_",
        "{": r"\{",
        "}": r"\}",
        "~": r"\textasciitilde{}",
        "^": r"\textasciicircum{}",
    }
    out_chars: list[str] = []

View on GitHub (pinned to 39ea8a1c6d)