This is part 9 of my "Building an AI Job Copilot in Python" series — the parts are short, each one fixes one real problem from my graph: structured output, RAG without a vector DB, the first LangGraph graph, evals, testing nodes, and a two-part dedup layer.

Last month a reader asked me the question I had been avoiding. In part 7 I built a dedup layer: every judged posting gets a fingerprint and a cached verdict, so the judge model is not called twice for the same job. His question: what invalidates a verdict when your judging criteria change?

He was right to poke there. My fingerprint is a hash of the posting body. If I tighten my score bands or rewrite the judge prompt, every one of the cached verdicts was produced by rules that no longer exist — and my graph will happily serve them back as if nothing happened. There is no error, no warning, nothing in the logs. Just stale judgments wearing a fresh timestamp.

This post is the fix, in three moves: make the rules part of the cache identity, migrate the existing store by scoping instead of wiping, and dry-run a policy change on stored scores before shipping it.

The fingerprint knows the job, not the rules

Here is the fingerprint from part 7, stripped to the essentials:

# fingerprint.py — the part-7 version, and the policy-aware version import hashlib def fingerprint(body: str) -> str: """Content-only fingerprint from part 7.""" cleaned = " ".join(body.split()).lower() return hashlib.sha256(cleaned.encode()).hexdigest()[:16] def policy_fingerprint(body: str, policy_id: str) -> str: """Same body, but the verdict rules are part of the identity.""" cleaned = " ".join(body.split()).lower() payload = f"{policy_id}\x00{cleaned}" return hashlib.sha256(payload.encode()).hexdigest()[:16] if __name__ == "__main__": body = "Senior Frontend Engineer - React / TypeScript - Remote EU" print("body only :", fingerprint(body)) print("policy A :", policy_fingerprint(body, "policy-2026-11")) print("policy B :", policy_fingerprint(body, "policy-2026-12")) 

Running it makes the gap obvious:

body only : 10d5daec57414579 policy A : db29e408ef5ace79 policy B : 23ec4cc6a596a227 

Same body, three identities. The content-only version cannot tell "same job, same rules, reuse the verdict" apart from "same job, different rules, do not reuse". A cache hit needs both facts, so both belong in the key.

Make the rules a value, not an assumption

The first honest thing I have to admit: there is no automatic way to know "the rules changed" unless the rules themselves are identifiable. My judge rules are a prompt file plus score bands, so I made them produce an id in two ways — a manual version bump that reads nicely in logs, and a derived id computed from the exact bytes that define the rules:

# policy.py — make "what the rules are" a value, not an assumption import hashlib from pathlib import Path # Bump this by hand when you change the rules and want an explicit, # human-readable version marker. Cheap, and it reads in the logs. POLICY_VERSION = "2026-12-bands" def derived_policy_id(prompt_path: str, bands: dict[str, tuple[int, int]]) -> str: """Auto-derive a policy id from the exact bytes that define the rules.""" prompt = Path(prompt_path).read_text(encoding="utf-8") material = prompt + "\n" + repr(sorted(bands.items())) return "policy-" + hashlib.sha256(material.encode()).hexdigest()[:8] if __name__ == "__main__": SCORE_BANDS = {"strong": (55, 90), "maybe": (35, 70), "weak": (0, 20)} print("manual :", POLICY_VERSION) print("derived :", derived_policy_id("judge_prompt.txt", SCORE_BANDS)) 

Output:

manual : 2026-12-bands derived : policy-41f21464 

The derived version closes the failure mode I actually have: I edit a prompt at night, forget to bump any constant, run the graph in the morning. With a derived id, the id changes the moment the bytes change — I do not have to remember anything. If you prefer reviewable bumps, the manual version is fine; the mistake it allows is one you would catch in a diff.

Migrate by scoping, not wiping

The migration decision was easier than I expected, for one uncomfortable reason: the store does not keep the posting body, only its fingerprint. So I cannot recompute fingerprints for existing rows under the new scheme — the input is gone. That kills the "re-key the table" option outright.

Wiping the table would work, but it throws away the other thing I care about: the old verdicts are evidence. If I want to quantify what a policy change actually does, I need old and new verdicts side by side. The fix is to keep the old rows and scope every lookup by policy:

# seen_store.py — scope the cache by policy instead of wiping it import sqlite3 class SeenStore: def __init__(self, db_path: str, policy_id: str) -> None: self.conn = sqlite3.connect(db_path) self.policy_id = policy_id def ensure_policy_column(self) -> None: """One-way migration: old rows keep their data under 'legacy'.""" cols = {r[1] for r in self.conn.execute("PRAGMA table_info(seen_jobs)")} if "policy_id" not in cols: self.conn.execute("ALTER TABLE seen_jobs ADD COLUMN policy_id TEXT") self.conn.execute( "UPDATE seen_jobs SET policy_id = 'legacy' WHERE policy_id IS NULL" ) self.conn.execute( "CREATE INDEX IF NOT EXISTS idx_seen_policy ON seen_jobs(policy_id)" ) self.conn.commit() def lookup(self, fingerprint: str) -> dict | None: """A hit only counts if it was judged under the CURRENT policy.""" row = self.conn.execute( "SELECT verdict, score FROM seen_jobs" " WHERE fingerprint = ? AND policy_id = ?", (fingerprint, self.policy_id), ).fetchone() if row is None: return None return {"verdict": row[0], "score": row[1]} def remember(self, fingerprint: str, url_key: str, verdict: str, score: int) -> None: self.conn.execute( "INSERT OR REPLACE INTO seen_jobs" " (fingerprint, url_key, verdict, score, policy_id)" " VALUES (?, ?, ?, ?, ?)", (fingerprint, url_key, verdict, score, self.policy_id), ) self.conn.commit() 

I tested this exact migration on a toy database with one pre-existing row: under the new policy id the legacy row returns None from lookup() — no hit, judge gets called once, verdict gets stored under the current policy. Then everything works as before. Cold cache for exactly one run, old data intact.

I kept both layers of protection on purpose. Since policy_fingerprint() embeds the policy id, a legacy-fingerprint row can never collide with a new-fingerprint row anyway. The policy_id column and the AND policy_id = ? guard are belt-and-suspenders against the day I (or an LLM refactoring session) quietly switch lookup() back to the plain fingerprint() — the schema itself says "this cache is policy-scoped."

Dry-run the bump before you ship it

This is the part I did not plan and now like the most. If verdicts are derived from scores through bands, and I have stored scores from the last run, I can preview a policy change with zero LLM calls: reuse measured scores, re-derive the verdict under old and new bands, count the movement.

# drift_report.py — dry-run a policy change before you ship it from fingerprint import policy_fingerprint # The part-4 score bands, old vs new. OLD_BANDS = {"strong": (55, 90), "maybe": (35, 70), "weak": (0, 20)} NEW_BANDS = {"strong": (60, 90), "maybe": (40, 70), "weak": (0, 20)} def verdict_from_score(score: int, bands: dict[str, tuple[int, int]]) -> str: for verdict, (low, high) in bands.items(): if low <= score <= high: return verdict return "weak" def drift_report( scores: dict[str, int], # job title -> judge score, measured once old_bands: dict[str, tuple[int, int]], new_bands: dict[str, tuple[int, int]], ) -> str: flipped = [] for title, score in scores.items(): if verdict_from_score(score, old_bands) != verdict_from_score(score, new_bands): flipped.append(title) changed = len(flipped) total = len(scores) rate = changed / total if total else 0.0 return f"{changed}/{total} verdicts move ({rate:.0%}): {flipped}" if __name__ == "__main__": # Scores measured under the current judge, once. No LLM calls in the dry run. measured_scores = { "Senior React dev, remote EU": 72, "Frontend lead, hybrid NL": 61, "React dev, fintech, UK": 58, # dead centre of the grey zone "React dev, fintech, UK (repost)": 57, "Junior React, junior salary": 22, "Fullstack React+Node lead": 66, "React contractor, 6 months": 44, "React dev, agency, low pay": 41, "Frontend architect, remote": 63, "React dev, undocumented stack": 39, # tips over with the new bands "Senior Angular dev": 31, "React + legacy jQuery, onsite": 47, } print(drift_report(measured_scores, OLD_BANDS, NEW_BANDS)) 

The output for this toy corpus:

3/12 verdicts move (25%): ['React dev, fintech, UK', 'React dev, fintech, UK (repost)', 'React dev, undocumented stack'] 

And that single line told me more than any prompt-tweak session ever did: nudging the bottom of strong from 55 to 60 does not move clear yeses or clear nos — it moves exactly the postings sitting in the grey zone. That is also where the honest A/B from earlier pays off: with old-policy rows still in the table, the same report runs on real stored verdicts after the bump, not just on band arithmetic. Two different mechanisms, one question: did this change move the verdicts I actually care about, or only the borderline noise?

One honest limitation: this dry run is only exact for band changes. A prompt rewrite can shift the scores themselves, not just how they map to verdicts, so the preview under-estimates its drift. For prompt changes I fall back to the eval corpus from part 4 — same idea, but the model has to actually run.

What I actually learned

Three things, in the order I got them wrong:

  • A cache identity must include the rules that produced the value. Content-only keys silently serve results from a policy that no longer exists. I shipped two dedup parts before noticing.
  • You cannot migrate what you did not store. No body in the table means no re-keying. Scoping by a policy column is the honest option: one cold run, old evidence kept.
  • A policy change is a deploy, not an edit. Bump the id, migrate the store, dry-run the drift, then ship. The report costs nothing — the scores are already paid for.

The bump itself, policy-41f21464, is where I leave the series for now. Next part is probably the attempt ledger idea from another comment on part 7: fingerprint says "this job was judged", but nothing says "this run got halfway and died" — resumable state for the graph.

If you are building something similar and hit the same wall, the one-line summary is: hash the rules, not just the data.

I write one post a week about this copilot, including the parts where I get it wrong first. Follow me here on dev.to if that sounds like your kind of reading, and if you missed the similarity half of the dedup layer, start with part 8.