Alejandro Ashes
AI Alchemy 13 min

Canon as a Graph: Building a Spoiler-Aware Lore Engine

A world bible in a folder is a document you consult. A world bible as a typed graph is a place a reader can walk around inside. Here is how to model a saga as connected entities, gate its reveals by reading position, and let AI populate it without leaking the ending.

Canon as a Graph: Building a Spoiler-Aware Lore Engine

A world bible usually lives as a document. A folder of notes, a private wiki, a spreadsheet of characters, a timeline nobody else can read. It works as a memory aid for the author and as almost nothing else, because a document is something you consult, one search at a time, when you already know what you are looking for.

A saga with a real world inside it deserves a better container. Model the world as a graph, where every character, faction, realm, artifact, and event is an entity, and every connection between them is a typed relationship, and the world bible stops being a document you consult and becomes a place a reader can walk around inside. Reading about a vampire princess leads you to the relic fused over her heart, which leads you to the entity that forged it, which leads you to the order hunted nearly to extinction for opposing it. You do not read a graph front to back. You traverse it, and the traversal is how the coherence of the world reveals itself.

This post is the build. The data model, the spoiler discipline that makes the graph safe to show a stranger, the role AI plays in filling and checking it, and why the whole structure earns its keep twice.

Why a Graph Beats a Document

A document encodes the world as prose, which means every relationship is implicit in a sentence somewhere. The connection between a character and the artifact she carries exists only as long as you remember which paragraph mentioned it. Scale that to a saga with hundreds of moving parts and the document becomes a thing only its author can use, and only on a good day.

A graph encodes the relationships as data. The character entity and the artifact entity each exist once, and the connection between them is a typed edge: “wields,” “forged by,” “hunted by,” “sworn to.” Once relationships are first-class, three things become possible that a document cannot offer.

You can traverse. From any entity you can see everything connected to it and step to any of those, which turns reference into exploration.

You can query. Show every faction aligned to a given force, every character who died in a given book, every artifact tied to a given realm. The questions answer themselves because the structure holds the answers.

You can audit. A graph makes contradictions visible. If two entities claim incompatible facts, the conflict sits in the data where it can be found, rather than buried across two chapters written a year apart.

The cost of the graph is that you have to decide, up front, what your entity types and relationship types are. That cost is the whole discipline, and it is worth paying.

The Data Model

Start with entity types, the categories of thing your world contains. A saga of dark fantasy might use characters, factions, realms, artifacts, events, and forces. Keep the list short at first. Every type you add is a type you have to maintain, and most worlds need fewer than you think.

Each entity gets a stable identifier (id), a display name, a type, and a body of description. The identifier is the part that matters most, because it is what relationships point at. Names change, descriptions grow, but the id stays fixed so that an edge written today still resolves a year from now.

Then the relationships, which are the reason the graph exists. A relationship has a source entity, a target entity, and a type that names the connection. “Faviana wields the Relic.” “The Relic was forged by the entity.” “The order opposes the entity.” Typed edges carry meaning that a generic link does not, and the types become a controlled vocabulary you reuse across the whole world so the graph stays consistent.

In practice an entry stays small and readable:

{
  "id": "the-relic",
  "type": "artifact",
  "name": "The Relic",
  "gate": "book-1",
  "links": [
    { "rel": "wielded-by", "to": "faviana" },
    { "rel": "forged-by", "to": "the-entity" }
  ]
}

The whole Codex is an array of these, and everything else in this post is built on top of that array.

Two fields turn a flat reference into a living structure. The first is the relationship type vocabulary itself, kept small and deliberate, so that “allied with” and “sworn to” and “serves” do not multiply into a dozen near-synonyms that fracture the graph. The second is the spoiler metadata covered in the next section, which is the field that makes the whole thing safe to show.

Stored as structured data, this whole model is a set of entity records and edge records, in whatever format your site already builds from. The site reads the structure and renders each entity as a page with its description and a list of its connections, each connection a link to the entity on the other end. That rendering is the Codex, and it costs nothing to operate because it is static data the build turns into pages.

Spoiler-Awareness Is the Hard Part

A reference work that dumps every reveal on a first-time reader has betrayed the reader. The reason most authors never publish their world bible is that the world bible knows the ending, and showing it would ruin the story for the exact audience most likely to seek it out: the engaged reader, partway through, hungry for more of the world.

The fix is to make the graph aware of when each fact is allowed to be known. Every entity, and every relationship, and even individual facts within an entity, carry a gate: the point in the reading order past which this knowledge is safe. A character’s surface description is open from the start. The revelation of that character’s true identity is gated to the book where it lands. The deepest mechanism behind a faction stays sealed until the volume that earns it.

That gate drives the rendering. A reader who has declared no progress sees only the open layer: the descriptions and connections that spoil nothing. A reader who has finished a given book unlocks the facts gated to that book and earlier. The late revelations stay hidden behind a deliberate choice to see them, so the reader who wants to be surprised stays surprised and the reader who wants everything can ask for everything.

The cleanest way to track progress is the reading position you already have. If readers consume the fiction on your own site, the site knows how far each reader has gone, and the Codex can unlock in lockstep with the reading. No accounts, no logins, just the graph respecting the order in which a reader is allowed to know things. A reference that respects that order has stopped being a leak in the story and become part of it.

The discipline this demands is real. Every fact you add forces the question of when it is safe, and getting that wrong in the unsafe direction spoils a reader who trusted you. Build the gate into the act of authoring each entry, rather than bolting it on later, and the graph stays safe by construction.

Where AI Fits

A graph of hundreds of entities is a large amount of writing and a large amount of bookkeeping, and this is where AI earns its place in the pipeline. The role is narrow and powerful: populate and audit, under the constraint of canon.

Population. The source material is the manuscript itself. Hand a model a finished book and the existing graph, and ask it to propose the entities and relationships the book introduces, each with a draft description and a proposed spoiler gate. The model is good at extraction, at noticing that a minor character recurs enough to deserve an entry, at drafting a serviceable first description that a human then sharpens. The human stays in the loop on every gate, because the cost of a model misjudging what counts as a spoiler is a betrayed reader, and that judgment belongs to the author.

A prompt pattern that works:

“Read the attached manuscript and the current entity list. Propose the new entities and relationships this book introduces, each with a one-paragraph draft description, a proposed gate, and the chapter that justifies it. Do not modify existing entries; flag conflicts with them instead.”

Audit. The graph becomes the model’s reference. Feed it the structure and ask it to find contradictions: two entities asserting incompatible facts, a relationship that points at an entity that no longer exists, a description that mentions a reveal gated later than the description itself. The graph makes these failures findable, and the model is a tireless reader that surfaces them faster than a human rereading the whole world.

The guardrail matters as much as the generation. Any text a model proposes for the graph should pass the same evaluation you would apply to generated prose anywhere: a check for voice and register failures, for the banned constructions your style forbids, for canon contradictions, and for spoiler leaks. Only output that clears the guard reaches the graph. The model accelerates the work and the author and the guard keep it honest.

The Build Earns Its Keep Twice

A spoiler-aware lore graph is a product feature, and it is also something else worth naming for any author thinking about positioning. It is the most demoable artifact in the whole stack.

As a product, the graph deepens the world. It turns the world bible from a private folder into a public destination, gives engaged readers somewhere to go between books, and lays the foundation for everything downstream: a printed sourcebook compiled from the same data, a game grounded in the same canon, a companion that can answer questions about the world without leaking its secrets.

As a positioning artifact, the graph is a clean, technical, narratable piece of work. A typed knowledge graph with access control, populated and audited by AI under guardrails, rendered statically so it costs nothing to run, is exactly the kind of thing that demonstrates capability to anyone evaluating how an author thinks about systems. The same structure that serves the reader serves as a case study, and building it once pays in both directions.

A World a Stranger Can Wander

The world bible does not have to stay a document only its author can read. Modeled as a graph of typed entities and typed relationships, aware of who is allowed to know what and when, it becomes a place readers explore and a foundation the rest of the world is built on.

The hard part is the spoiler gate, and the hard part is the point. A reference that knows the ending and shows it anyway is worthless to the reader who matters most. A reference that holds its secrets until the reader has earned them is part of the story.

Build the graph so a stranger can wander it safely, and the world stops living in your folder and starts living in theirs.

✦  Ballads of Eldritch Metal
—
Alejandro Ashes
0:00 0:00