“Stay in-lore” prompt engineering is less about clever wording and more about giving the model the right boundaries: what is true in the setting, what cannot be true, and how to respond when the player pushes outside canon. If your game world has factions, eras, forbidden knowledge, and tone rules, your prompt should encode those as constraints—then provide a safe fallback when information is unknown.
1) Define the job: narrator, NPC, or rules referee
Before you write a single line of lore, clarify what the model is allowed to do. A narrator can summarize events; an NPC can only speak from their viewpoint; a rules referee should cite mechanics but never invent new ones. Mixing roles is one of the fastest ways to drift out of canon.
- Narrator: can describe scenes broadly, but should avoid revealing hidden plot unless permitted.
- NPC: must respect knowledge limits (region, education, social class, secrecy).
- GM assistant: can propose options, but must label speculation vs canon.
2) Provide a “Lore Contract” (what is true, what is forbidden)
Think of a lore contract as a short rulebook the model must follow. Keep it scannable and explicit. Good contracts include:
- Canon facts (timeline anchors, geography, key factions, technology level).
- Non-canon bans (no Earth brands, no modern slang, no new continents, no time travel if it doesn’t exist).
- Tone (grim, hopeful, pulpy, cozy), plus what to avoid (gore, sexual content, hate).
- Names & language rules (phonetics, honorifics, profanity level).
3) Add guardrails for uncertainty: “If you don’t know, do this”
Models drift when they feel pressured to answer. Replace that pressure with policy: if the player asks about unknown lore, the NPC should admit uncertainty, offer an in-world lead, or ask a clarifying question. This both preserves canon and produces better gameplay.
Uncertainty rule: When a detail isn’t in the provided lore, respond with one of: (1) “I don’t know” in-character, (2) a question to narrow scope, or (3) a lead that points to a known place/faction/record.
4) Use “knowledge windows” to keep NPCs believable
An NPC doesn’t have access to the setting’s wiki. Define a knowledge window: what they can know (local rumors, their guild’s doctrine), what they cannot (secret councils, other continents), and what they might misunderstand (propaganda, superstition). This stops the model from delivering omniscient exposition.
5) Prompt pattern: Canon → Constraints → Output format
Use a stable structure so you can iterate. Here’s a compact template you can adapt:
[ROLE]
You are: {NPC name}, {job}, in {location}, year {X}.
[CANON]
- Timeline: ...
- Factions: ...
- Magic/tech limits: ...
[CONSTRAINTS]
- Never mention: ...
- If unknown: admit uncertainty + offer a lead.
- Voice: {tone}, vocabulary: {rules}.
[OUTPUT]
Return:
1) NPC dialogue (1–3 paragraphs)
2) If needed: a single actionable hook for the player
6) Handle player attempts to break lore (without saying “I can’t”)
Players will ask for phones, helicopters, modern memes, or out-of-era weapons. Instead of refusing outright, redirect in-world: offer the closest analog that exists in the setting, or make it a rumor, scam, or misunderstanding.
- Replace: “There are no smartphones.” → “No ‘smart-stones’ like that exist; the courier guild uses sealed whisper-scrolls.”
- Reframe: “Can I buy a laser rifle?” → “The alchemists sell sun-glass lanterns—dangerous, rare, and regulated.”
- Gate: “Can I meet the hidden king?” → “That name is taboo; you’ll need a signet from the Black Archive.”
7) Practical testing: create a “lore drift checklist”
After a few sessions, you’ll see repeated failure modes. Turn them into tests you run on every revision:
- Does the NPC ever reveal secrets they shouldn’t know?
- Does it introduce new factions/places without permission?
- Does it break tech level, timeline, or tone?
- When uncertain, does it ask or redirect instead of inventing?
8) Tie it back to your club notes and recaps
If you’re using LLMs to summarize sessions or write recaps, apply the same contract: what happened at the table is canon; anything else must be labeled as “possible next session hooks.” For how we handle sourcing and verification, see About → How We Verify. For more articles in this series, browse the Blog.
Quick takeaway
In-lore prompting works when you treat prompts like rules documentation: explicit constraints, clear uncertainty behavior, and consistent output. Do that, and you’ll get NPCs that feel grounded—even when players try to derail the world.