Stop the model from making things up
Context
Our extractor sometimes reports a patent number or a claim limit that is nowhere in the document, and right now those values go straight into the analytics store. We use an LLM to pull claim level data out of patent documents: the publication number, the number of claims, the patent numbers the document cites, and for each claim its number, the claim it depends on, and the numeric range it states (for example "between 5 and 15 wt%"). Most of the time it is right. We want every extracted identifier and number to be traceable to the source document, and anything we cannot verify to go to a person instead.
Your task
- Check that every extracted identifier and number can be traced back to the document text. Harmless formatting differences should pass (
US 2019/0123456 and US20190123456, 1,200.00 and 1200, 5.0 and 5), but near misses must not (US 2019/0123457 for US 2019/0123456, 50 for 5).
- Check the claim structure. A claim that says it depends on another claim must refer to a claim number that exists in the document, an independent claim must not be reported as depending on something, the low end of a range must not be above the high end, and the number of claims you report must match the count the document states.
- Return a result that says what was verified. Create
verify.py with verify_extraction(text, extraction) -> dict returning:
{
"needs_review": bool,
"fields": { # one entry per field, keyed by path
"publication_number": {"value": ..., "verified": bool, "reason": str | None},
"claim_count": {...},
"cited_references[0]": {...}, # for every citation the model returned
"claims[0].claim_number":{...}, # plus depends_on, value_low, value_high, unit
... # for every claim the model returned
},
"issues": [str, ...] # human-readable, for the reviewer
}
value is exactly what the model returned. Don't drop, fix or silently skip anything: a missing or unparseable field is reported as unverified, and an extra claim is reported, not removed. A clean document should come back with every field verified and needs_review false. Then make process_document() in extract.py include these keys alongside extraction.
- Add tests for your checks in
tests/.
- Write
NOTES.md (5-10 lines): what formatting differences you chose to accept and which you reject, why, and what kinds of made-up values your checks would still miss.
What's here
llm.py model client (simulated model, see below). Treat it as an external model: don't edit it.
extract.py prompt + model call; returns the model's output as-is and never asks for review
data/claims/ 10 patent documents as text, each with a front page block and a claim set
tests/ existing tests (they pass now; keep them passing)
llm.py is a simulated stand-in for the model we use in production. It is deterministic, and some of the documents trigger the kinds of mistakes described above.
Running it
python3 extract.py data/claims/*.txt # extract every document and show whether it needs review
python3 -m unittest discover -s tests -v # run the tests
Python 3.11, standard library only.
Time
Aim for about 25-30 minutes. You don't need to finish everything; we care more about how you approach it than about completeness.