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

section cites unknown bibliography key

Error message

section {sec.id!r} cites unknown bibliography key {key!r}

What it means

Reference-integrity guard: a section's cites list names a bibliography key that no BibEntry defines, so LaTeX \cite would render an unresolved '?' reference.

Solutions

  1. Add the missing BibEntry to paper.bibliography
  2. Fix typos in the section's cite key so it matches an existing entry
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/54-paper-writer/code/main.py:96 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/8d6e2288a0cb027c. Report an issue: GitHub.

Appendix: source

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

        raise PaperValidationError("title is empty")
    if not paper.abstract.strip():
        raise PaperValidationError("abstract is empty")

    fig_ids: set[str] = set()
    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"\{",

View on GitHub (pinned to 39ea8a1c6d)