Skip to main content
Brussle judges each edit to a contract section against the section as your legal team last approved it, however many rejected edits come between. You keep the flagged sections as a query that stays current, a webhook tells you when a section enters or leaves it, and your reviewers’ verdicts calibrate the judgment’s number on your data. The judgment reads the document as it is now beside 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?”
Without 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 as sec_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

The material_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.
The engine sees each path twice, once as it is now and once as it was:
The 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.
What each answer shows:
  • Revision 1 is the first evaluation, so the engine sees nothing under previous, the answer has no previous_revision, and the evaluation records first_revision: true. With nothing to compare, the engine usually answers with a low p.
  • 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 pending until Brussle judges it, and a query with answers: "fresh_only" leaves the section out meanwhile. When Brussle judges the edit, the engine sees revision 2 under previous. A longer notice period for one party usually makes p pass 0.5, so review is true. 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, p is 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 for material_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% interval and the fit that 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 review threshold 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 whose review 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.
A subscription on the same filter sends 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:
Each event carries the attributes named in include and the answer the filter reads, as a get returns them, but never state:
  • subscription.entered arrives after the edit, so you can open the section for a person.
  • subscription.exited arrives after the approval (with reason no_longer_matches) or when the section is deleted (with reason deleted), so you can close the review.
  • sequence grows with each change in the namespace. A retried event can arrive after a later one, so keep the highest sequence you saw for each subscription and document.
  • url is the document’s get, which you call with your own key when truncated is true.
Verify the signature of each delivery before you trust it, as receive webhooks shows.

Read what the engine compared

A fresh 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_revision is the baseline the engine saw. If it is not the approved revision, look at approved_at on the revisions between. A system that rewrites approved_at on every write moves the baseline on every write, and a system that does not change it on an approval never moves it.
  • context_truncated: true means the context passed max_tokens. Brussle cuts the previous.<path> entries first, so the engine saw the current text but not all of the earlier text. The answer is still fresh. Watch the judgment’s stats.truncation_rate (see cost and limits).
  • context holds the two renderings, keyed by path. Compare state.text and previous.state.text with 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 under previous. A failed answer keeps the last success’s previous_revision, along with its numbers.
  • The evaluation (at GET /namespaces/{ns}/evaluations/{id}) records previous_revision, or first_revision: true when the document had no stored rendering in its incarnation. A get with include=history,context (include_history and include_context in Python, includeHistory and includeContext in 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 fields nor previous.fields names 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.fields can name an image (such as images.photo, which shows as previous.images.photo), and an image that did not change between the two revisions counts once.
  • Over max_tokens, Brussle cuts the previous.<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_at as 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.