Ask the Model a Rules Question

On a busy evening at a neighborhood board game café, players argue about the rules at the tables, and staff can’t read eight rulebooks between orders. The café wants a rules desk: a player types a question, and a script answers from the café’s own rulebooks, names the game and page it used, and says so when the rulebooks don’t cover the question.

In this lesson, you’ll set up the project the course builds on and send a player’s question straight to a model. You’ll then compare its answer with the real rulebook page and see why a fluent answer isn’t enough for the café.

Set Up the Café’s Project

Text lessons build one project as you type along, with calls to your own provider. This lesson’s calls cost well under a cent each, and later calls that carry rulebook pages cost more, depending on your model and how much text each request sends. Videos show that project at work. Exercises run in your browser against a stand-in model, so they need no key. The final project assembles the rules desk.

The course assumes you can write async functions with await, handle a failed request, and run Node.js scripts that use npm packages. You also need an API key for OpenAI or Anthropic. The project ships with its model code, so you needn’t have built it yourself.

Get the starting project from the sample code download linked in the course’s first lesson, the Overview video. Unzip it and open a terminal in its folder. It holds:

  • data/rulebooks/, the rulebooks of the café’s eight most-played games, one plain-text file per game. Each page starts with a marker line such as == Page 3 ==. The games are small originals written for this course, so the models this course was tested on had never met their rules.
  • data/questions.json, a dozen questions that players asked at the tables, each with an id, a table number, and the text.
  • model/, the module that connects your code to the model. Its ask() function sends instructions and an input to your provider and returns the reply’s text, its token usage, and cutOff, which is true when the reply hits the output token limit. It also exports askForJson(), which returns a checked object, and streamAnswer(), which this course doesn’t use.
  • rulebook-text.js, small helpers for reading the rulebook files, which you’ll use when you split the rulebooks into chunks.
  • package.json, the file that lists two packages: Zod for checking data and a package that runs a small model on your own machine. You’ll meet that model in the next lesson.

Install the packages, then create .env from the template, or copy in a .env you already have from earlier work with ask():

Language: Windows PowerShell
PS> npm install
PS> Copy-Item .env.example .env
Language: Shell
$ npm install
$ cp .env.example .env

Open .env and set MODEL_PROVIDER to openai or anthropic. Then paste your key into the matching key line. Set MAX_OUTPUT_TOKENS=400 and MODEL_TIMEOUT_SECONDS=30. The project’s .gitignore already lists .env and node_modules/, so your key stays out of Git if you put the folder under version control.

Ask the Model About Card 23

The quickest rules desk sends the player’s question to the model and prints the reply, the way you’d type a question into a chat window. Question 9 in data/questions.json comes from table 1, where a player has drawn an action card in Night Market:

Language: JSON
{
  "id": 9,
  "table": 1,
  "text": "Night Market card 23 lets me 'peek'. Do I show the card to everyone after?"
}

Create ask-directly.js in the project folder. It reads the questions, picks question 9 with the array method .find(), and sends it through ask() with short instructions:

Language: JavaScript Filename: ask-directly.js
import { readFile } from "node:fs/promises";
import { ask } from "./model/index.js";

const INSTRUCTIONS = `You answer rules questions for players
at a board-game café. Answer in two or three sentences.`;

const text = await readFile("data/questions.json", "utf8");
const questions = JSON.parse(text);
const question = questions.find((entry) => entry.id === 9);

const reply = await ask({
  instructions: INSTRUCTIONS,
  input: question.text,
});
if (reply.cutOff) {
  console.log("Cut off: raise MAX_OUTPUT_TOKENS.");
}
console.log(`Table ${question.table}: ${question.text}`);
console.log(`Answer: ${reply.text}`);
console.log("Usage:", reply.usage);

Before you run it, make a prediction. Night Market was written for this course, so its rulebook wasn’t in the model’s training data when this course was written. Will the answer say that it doesn’t know the rule? Then run the script with node --env-file=.env ask-directly.js and open the collapsed block to compare:

Here’s one real run with OpenAI’s capable model, which also produced the Lantern Harbor run later in this lesson. The long answer line is wrapped for display. Your wording and token counts will differ, and an Anthropic model may be more or less cautious:

Language: Program Output
Table 1: Night Market card 23 lets me 'peek'. Do I show the card to everyone after?
Answer: No—“peek” means you look at the card privately. Don’t show it to
the other players unless the card or rulebook also tells you to reveal
it.
Usage: { inputTokens: 49, outputTokens: 38 }

The model didn’t say it had never seen the game. It opened with a firm “No” and a sensible-sounding reason, then added a condition, “unless the card or rulebook also tells you to reveal it.”

On December 1, 2026, model/config.js priced the capable model at $2 per million input tokens and $10 per million output tokens. At those prices, the 49 input and 38 output tokens cost about 0.05 cents.

The answer reads well, so check it against the rulebook. Open data/rulebooks/night-market.txt and find card 23 on page 3:

Language: Text
Card 23, Peek: look at the top card of the deck, then show it to
all players. You may leave it on top of the deck or put it at the
bottom.

Card 23 is exactly the exception the model’s condition mentions, but nothing in the request said so, because the card’s text never reached the model. Its firm “No” wasn’t based on a rulebook, and its condition leaves the player to find out what the card says. A player who acts on the first word keeps the card hidden. With this script on the café’s tablets, table 1 could play the card wrong, with no warning.

See Why the Answer Sounds Right

A language model doesn’t look a rule up. It predicts the text that’s likely to follow your instructions and question, based on the text it was trained on. In many games, “peek” does mean a private look, so a private look is the likely continuation. The model has nothing that ties its answer to Night Market’s page 3, so it can be fluent and wrong at once.

Sometimes the model hedges instead. Change the 9 in the .find() line to 10, a question about Lantern Harbor, and run the script again. This real run asked for the rulebook (its answer wrapped for display):

Language: Program Output
Table 6: Lantern Harbor: can I trade fish for oil with someone who isn't next to me?
Answer: I’m not sure whether Lantern Harbor restricts fish-for-oil
trades to neighbors. Can you share the trading rule and clarify whether
“next to me” means seated beside you or adjacent on the board?
Usage: { inputTokens: 48, outputTokens: 70 }

That’s a better answer, but your code can’t count on getting it, and nothing in the reply tells your code which kind it got. However, the hedge points the way, because the model asked for the rule it was missing.

If the difference between predicting and looking up still feels fuzzy, use the button above to open the mentor with that question.

For the rest of the course, you’ll hand the model the right page. First, your code finds the few rulebook pages that match the question. Then it sends those pages with the question. It tells the model to answer only from them, to name the game and page, and to say so when the pages don’t cover the question.

The checks at the end of the course make sure every cited page was really sent. That won’t make every answer right, but both a player and your code can check each answer against a real rulebook page.

Check Your Understanding

These questions use the café’s project from this lesson. Answer them before you open the answers:

  1. The model’s answer about card 23 opened with the wrong rule, yet the script ran without an error. Why didn’t anything in the code catch it?
  2. A colleague suggests adding “Don’t make up rules” to the instructions and calling the feature done. Why isn’t that enough for the café?
  3. Why does the course use games written for it instead of popular published games?
  1. The call succeeded because the provider returned text and ask() passed it on. Nothing in the request or the reply ties the answer to the rulebook, so the code has nothing to check it against.
  2. The instruction changes what the model is likely to write, but the model still has no copy of page 3. It may hedge more often, and it may even guess right, but it can’t reliably give the café’s rule without the page, and your code can’t tell a hedge, a guess, or an invented rule from the real one.
  3. Their rules weren’t in the model’s training data when this course was written, so the model can’t lean on a memorized rulebook, and a wrong turn like card 23 shows up clearly. A correct answer still isn’t proof that your code sent the right pages, because a model can guess a common rule. With a famous game, memorized rules would also mask missing source pages, which is why the rules desk will name the page it used and check that page was sent.

To find the right pages, your code needs a way to compare a question with a page by what they mean, even when they don’t share the same words. In the next lesson, Turn Text Into Vectors, you’ll turn text into lists of numbers that make that comparison possible.

Become a Member to join the conversation.