# Database tips: building a database your company can trust

These are the habits we follow when we build databases for our own work. They're written for a company building an internal database from its own records and public sources, whether people or AI agents will use it.

## 1. Start from the questions

- Write down the questions the database must answer and who asks each one. Every table and field should trace back to one of them.
- Name the whole scope of what a table holds, in plain words (`contracts`, `customer_payments`). No nicknames, no project code names, no initials only the builder knows.
- Keep version labels out of every name: no `_v2`, `_final` or `_new`. The current build always has the plain name; versions live in a build log.

## 2. List your sources, and their terms

- Keep a register with one row per source: who publishes it, its exact address, what it covers, how often it changes, when you fetched it and how you loaded it.
- Record each source's terms of reuse when you first load it. Some sources may be republished, some need credit, some bar uses such as AI training or commercial use, and some are private. The limit travels with the data, so anyone who later exports or shares a table is warned first.
- Keep raw downloads apart from everything you derive from them, and never edit them. A fix goes in a separate corrections file or in the loading script.

## 3. Provenance on every field

- Every table, and every row that was made differently from its neighbours, says how it was made: copied from an official source, computed by a script, read by a model or fixed by hand.
- Every record points back to its source (a link to the page or document) so anyone can check it.
- In records people edit by hand, keep the source, who said it and the date beside each important field. A value with no source isn't written in.

## 4. Enrich with models, and log what they did

- Do the cheap, exact steps first with scripts: download, split, match identifiers. Spend model reading only on what scripts can't do, such as reading a clause or classifying what a document says.
- Log every model read: which model, which prompt, what it read, when, and how many tokens it used. You'll need this to explain a figure and to price the next read.
- Test on a small sample before a large run, and never load a test or a partial pass into the database.

## 5. Build an answer key

- Check a random sample by hand, or with a second model, against the source texts, and report accuracy field by field with its range.
- Say where the answer key came from and its limits. Experts disagree on some calls, so no key is perfect.
- Publish what would raise accuracy (a second read, more source records) and its rough cost.

## 6. Give people a viewer

- A database isn't done until a person can browse it: search, sortable tables and one page per record.
- Every person, company, place or document the viewer names opens its own profile, with the source of every line.
- Lead with the questions the database answers, then the reference tables behind them.

## 7. Give agents an interface

- Offer bulk downloads, a read-only query interface (an API or an MCP server) and a short guide an AI agent can read first: what each table holds, how they join and worked example queries.
- Keep a standing rules file for agents: open the data read-only, check the source register before reusing anything, and show the queries behind an answer.

## 8. Store each fact once

- One person, company or place gets one identifier that means the same thing in every table. Keep every spelling you've seen as an alias of that identifier, so a new load never creates a duplicate.
- Store a shared mapping once, in a small lookup table, and join it back with a view.
- Run duplicate checks on every build over every record: same names after normalizing case, spacing and "&" against "and", and aliases that point to two different entities.
- Identifiers are never reused. A retired identifier never names something new.

## 9. One format, one layout

- Use one database format for working data and keep flat files (CSV, Parquet) for exports.
- Use one folder layout everywhere the project lives: raw downloads, scripts, work files, outputs and an archive folder for superseded material, each dated and labelled.
- Before you add a new layer of analysis, archive the one it replaces. A database should hold one current answer per question.

## 10. Types that mean one thing

- Dates are dates (with a note of their precision when partial), yes-or-no fields are true or false with blank for unknown, money is in one currency with the unit in the name, and lists are lists.
- Blank means none or unknown. Never use an empty string or a word like "none" or "n/a" in a value field.

## 11. A documentation set people will read

- README: what it is, why it exists, how it works and how to rebuild it.
- SCHEMA: every table and column, with its meaning, type, source and row count, generated from the database itself.
- SOURCES: one entry per source, with its terms.
- CHANGELOG: what changed in each build, newest first.
- GAPS: open problems and known limits, one line each, closed when fixed.
- Update them in the same step as the change. A stale doc is a bug.

## 12. Checks on every build

- Write builds to a copy and swap it in only when the checks pass, so a failed build never damages the working database.
- Check names, types, identifiers and provenance on every build, and fail the build when a link points at something that no longer exists.
- Compare file size with data size and row counts with distinct keys, to catch repetition early.
