previous, which is either the revision its last answer saw or the revision last approved. previous is the one relation that reads no other document, so use it when your question is about a change rather than about a document:
- “Did the renewal clause change between these two revisions of the contract?”
- “Did this listing change in an important way after we approved it?”
- “Does this edit try to get past the moderation that the original passed?”
previous, you would build a diff job, an edit lock and a second review queue yourself. The examples use ns = db.namespace("acme/prod"), which needs a key whose scope covers acme/prod (such as acme/*), since the key you got at sign-up cannot reach it, and only an organization with a card on file can create one that does (get an API key).
Compare with the approved revision
Keep one document for each contract section (such assec_12), with attributes.kind set to contract_section and the section’s state.heading and state.text. Your system writes attributes.approved_at when the legal team approves a section, while the other party’s edits change state.text and never approved_at.
Name approved_at as the anchor of previous, since without an anchor the baseline moves forward with each answer. An edit the legal team rejected then becomes the baseline for the next one, and the other party can move a section far from what was approved, one small redline at a time. With an anchor, the baseline moves only when the anchor’s value changes, and then it moves to the revision that has the new value. Until you first set the anchor, the baseline is the first revision the judgment judged.
If the legal team rejects revision 3 instead,
approved_at stays as it was, so Brussle compares each later edit with revision 2 until the next approval.
Create the judgment
Thematerial_change judgment asks whether an edit changed the section in a way that matters since its approval. It needs no confirm, since a judgment with previous and no related never does.
review threshold of 0.5 is a starting value, so record the reviewers’ verdicts and set the threshold from them.
The change detection starter creates the same judgment from your paths, but without an anchor. To compare with the approved revision, add anchor to previous in the definition that the starter’s dry run returns.
Create the judgment before you write the sections, since Brussle does not judge a document written before the judgment was created until the document changes or a backfill judges it.
Write the edits and approvals
write_section writes the section and waits up to 10 seconds for its answer. The first answers of a new judgment can take longer, so answer_after keeps reading for at most 60 seconds, until the answer is fresh and comes from a new evaluation.
- Revision 1 is the first evaluation, so the engine sees nothing under
previous, the answer has noprevious_revision, and the evaluation recordsfirst_revision: true. With nothing to compare, the engine usually answers with a lowp. - Revision 2 changes the anchor value, so the baseline moves to it. The answer compares the approved revision with itself and records
previous_revision: 2. - Revision 3 is the edit. The answer reads
pendinguntil Brussle judges it, and a query withanswers: "fresh_only"leaves the section out meanwhile. When Brussle judges the edit, the engine sees revision 2 underprevious. A longer notice period for one party usually makesppass 0.5, soreviewistrue. Do not expect the same number each time. - Revision 4 renders the same as the last revision judged, so the context hash is the same and the answer stays (no engine call, no evaluation and no bill).
- Revision 5 changes the anchor value again, so the answer compares revision 5 with itself,
pis usually low, and the section leaves the review queue. Brussle compares each later edit with revision 5.
Record the reviewers’ verdicts
When a reviewer decides whether a flagged edit was material, post the verdict as an outcome formaterial_change (true or false), or let an outcome rule make one from the write that records the decision. Post the edits judged not material too, so that the judgment has outcomes of both kinds.
- Once the judgment has 50 outcomes (15 of each kind), each answer carries a corrected number with a 95%
intervaland thefitthat made it, as soon as the correction beats the engine’s numbers on held-out outcomes. - Once it has 100 outcomes (20 of each kind), the threshold recommender (Team plan and above) finds the
reviewthreshold that meets a precision or recall target, such as “send edits to legal review, and be right 90% of the time”. - The report shows how well the numbers match your reviewers’ verdicts.
Keep the review queue
The review queue is a query for the sections whosereview threshold is true, with answers: "fresh_only" to leave out each section whose answer is pending, stale or failed. Brussle keeps the query current, so a section enters when an edit’s answer passes the threshold and leaves after the approval.
subscription.entered when a section starts to match and subscription.exited when it stops. The subscription sees only settled answers, so a pending answer never sends an event. Create a webhook endpoint first, then the subscription:
include and the answer the filter reads, as a get returns them, but never state:
subscription.enteredarrives after the edit, so you can open the section for a person.subscription.exitedarrives after the approval (withreasonno_longer_matches) or when the section is deleted (withreasondeleted), so you can close the review.sequencegrows with each change in the namespace. A retried event can arrive after a later one, so keep the highestsequenceyou saw for each subscription and document.urlis the document’s get, which you call with your own key whentruncatedistrue.
Read what the engine compared
Afresh answer can have incomplete inputs, since fresh says that the answer agrees with the current revision and nothing about whether the engine saw the baseline you intended, or the whole text. Open the evaluation before you connect the queue to your workflow, and again whenever an answer surprises you:
previous_revisionis the baseline the engine saw. If it is not the approved revision, look atapproved_aton the revisions between. A system that rewritesapproved_aton every write moves the baseline on every write, and a system that does not change it on an approval never moves it.context_truncated: truemeans the context passedmax_tokens. Brussle cuts theprevious.<path>entries first, so the engine saw the current text but not all of the earlier text. The answer is stillfresh. Watch the judgment’sstats.truncation_rate(see cost and limits).contextholds the two renderings, keyed by path. Comparestate.textandprevious.state.textwith what your system holds for the two revisions.
Where it shows
- The answer has
previous_revision, the revision its previous rendering came from, unless the answer showed nothing underprevious. Afailedanswer keeps the last success’sprevious_revision, along with its numbers. - The evaluation (at
GET /namespaces/{ns}/evaluations/{id}) recordsprevious_revision, orfirst_revision: truewhen the document had no stored rendering in its incarnation. A get withinclude=history,context(include_historyandinclude_contextin Python,includeHistoryandincludeContextin TypeScript) returns the document’s evaluations, newest first, with both renderings, and the dashboard shows the same on the document’s page. - An id you delete and write again starts a new incarnation. The old incarnation’s renderings do not count, so the new incarnation’s first evaluation shows nothing under
previous.
How the baseline moves
previous.fields names paths of the document itself (state.*, attributes.* or images.*). Brussle renders them as fields renders them, each as a previous.<path> entry after the fields entries.
“Previous” is not the revision before the write, as you might expect. Brussle judges only the newest revision of a document, so two edits close together (or within the judgment’s debounce_ms) leave a revision that nobody judged, and a comparison with that revision would hide the first edit. After each successful evaluation, Brussle instead keeps two renderings beside the answer, the stored previous (which the answer compared against) and the stored current (the revision it judged). Without an anchor, they move like this:
Brussle compares two quick edits with the last answer, not with each other. A failed evaluation changes nothing, so its retry compares with what the last success saw. With an anchor, the stored previous moves only when the anchor value changes, and then it moves to the rendering of the revision that changed it.
A changed section reads
stale (document_changed) under manual and periodic until something judges it, while under on_read a read starts the judging (see freshness).
After a new version
previous and its fields are part of the judgment’s version, although the stored renderings carry across versions. When a new version names other paths in previous.fields (or another max_chars), the next evaluation of each document shows under previous only the paths both versions name. Brussle stores the new paths after that success, so the next edit compares as usual. A change to fields alone leaves the stored renderings as they are.
After you activate the new version, each answer from the earlier one reads stale (older_version) until the document changes or a backfill judges it. Confirming the version’s shadow report starts that backfill.
Cost and limits
previous roughly doubles the context for the paths it names, and the size of the context sets the cost (see size classes). Name only the paths where a change matters, and keep them short (a heading and a section’s text, not the full contract).
- A re-upsert with the same values costs nothing, as revision 4 shows. You can send every record again each night if you like, and Brussle bills only the real edits, one row each.
- An edit to a path that neither
fieldsnorprevious.fieldsnames changes nothing the engine sees, so it costs nothing. - An anchor costs one attribute value beside the stored renderings, and one row for each approval write.
- Images.
previous.fieldscan name an image (such asimages.photo, which shows asprevious.images.photo), and an image that did not change between the two revisions counts once. - Over
max_tokens, Brussle cuts theprevious.<path>entries first (the last entry first) before it cuts any field, so the current revision’s text shows in full. On an engine that reads images, Brussle leaves out whole images, the current revision’s images included, before it cuts any text. - Storage. The renderings are part of the namespace’s data, with at most two stored contexts for each document and each judgment with
previous.
Other uses
- Listings after approval. A marketplace approves a listing, then the seller edits it. Read the title, the price and the description, with
attributes.approved_atas the anchor, and ask whether the edit changes what is sold, its condition or its price enough for a second review. - Change monitoring. For supplier records, product catalogues or policy pages that you import again each night, Brussle judges only the real changes, each against the last answer.
- Profile edits. “Does this profile edit change the payout details and the email together?” Read the email, the payout details and the display name with no anchor, so that Brussle compares each edit with the last one judged.