Skip to main content
You judge each post under the policy it points at. Before you change the policy, you see how many answers the change would flip, how many of those flips the engine’s own variation would cause anyway, and what it would cost. When you write the change, Brussle judges the affected posts again and the review queue follows. The example is a forum, where each post points at the forum’s policy (house_rules) through attributes.policy_id, and the judgment breaks_policy reads the policy as the post’s referenced document. The same shape fits listings against listing rules, or order lines against a returns policy, and a change to one of several rulebooks judges again only the posts that point at it. The examples use ns = db.namespace("acme/forum"), which needs a key whose scope covers acme/forum (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).

Create the judgment from the policy starter

The forum’s judgment comes from the moderation.under_policy starter. Create it before you write the posts, since an on_change judgment judges the documents written after it exists and earlier ones wait for a backfill.
Make max_tokens large enough for the policy and a long post together. Over max_tokens, Brussle leaves out the whole policy before it cuts any of the post, so the engine judges the post with no policy, and the starter’s criteria say that such a post breaks nothing.
The starter sets max_tokens to 2,000. Send the create with dry_run: true and count the tokens of your policy, your longest usual post and the question. If they pass 2,000, raise max_tokens in the returned definition (a larger size class) or shorten the rules. You can edit the question or criteria there too, then create from that definition:
POST /v1/namespaces/acme%2Fforum/judgments
The SDKs send the same body with ns.judgments.create(body) (TypeScript) or ns.judgments.create(**body) (Python).
  • It judges only posts (kind post), so the policy itself is never judged or billed. It reads each post’s title and text, and the rules of the document named in attributes.policy_id when its kind is policy.
  • A post with no policy_id is judged with no policy shown, and the criteria say it breaks nothing.
  • A post whose policy does not exist (such as a deleted one) keeps its last answer, which reads stale (referenced_missing), so a hidden post stays hidden. Writing a policy with that id again judges the posts again (see a missing referenced document).
  • Thresholds. Hide a post above hide (0.9), and send the posts between review (0.5) and hide to a person. Both are starting values (see record what moderators decide).
  • The fan-out debounce. After a policy change, Brussle waits for a quiet period (10 minutes by default) before it judges the posts again. This body sets one second for the walk-through, which you remove for production (see fan-out).
The first version builds a reference index on attributes.policy_id, unless the namespace has one. The create response lists it as a reference_index job in job_ids, and the answers are unavailable until the job is done.

What you confirm

Without confirm: true, the create returns its cost estimate and creates nothing:
replay counts the writes to the posts themselves and leaves out policy changes, so it says "excludes": ["fanout"] and lower_bound: true. The rolling limit caps what policy changes can cost at 300,000 posts judged again in any 30 days, here at most $75. confirm: true agrees to both amounts, and after it no policy change waits for a person (see what the replay estimate cannot count).

Write the policy and the posts

Write the policy first, since a post judged before its policy exists is judged with no policy shown.
fresh_answer reads the post for at most 120 seconds, until its answer is fresh and comes from a new evaluation. In the answer, p is the engine’s probability that the post breaks the policy, thresholds says which side of hide and review it is on, and watermark says which revisions it read, the policy’s included (see answers). An answer that reads unavailable can mean the reference index job is still running, so read the post again in a few seconds.

Simulate a change before you write it

The forum wants to add a rule against links to paid content. Send the proposed policy, as you would upsert it, to POST /v1/namespaces/acme%2Fforum/judgments/breaks_policy/simulate with the name of the relation that reads it:
  • relation must be one of the judgment’s relations that reads one referenced document. Brussle does not simulate a named list, and anything else is invalid_request.
  • The document must be one the write API would accept. Each image in its images must reference an image the namespace holds, and an image sent as a data URL is invalid_image.
  • sample is 1 to 1,000, 200 by default.
Brussle responds 202 with a simulation job and writes nothing. Read the job until its status is done or failed:
The job counts the posts that point at the policy and are inside the judgment’s re-judge scope (freshness.fanout.scope), which are the posts a write of the change would judge again. It picks sample of them at random, so each sampled post stands for the same share of them. It then judges each sampled post twice at the same moment, with the judgment’s active version and the same engine version, once with the current policy and once with the proposed one. Brussle never writes the proposed policy.

Review the result

The simulation is your review step. GET /v1/jobs/{id} shows simulation when the job is done:
  • population is the number of posts a write of the change would judge again, and sampled how many of them the simulation judged.
  • thresholds has an entry for each named threshold, counting the changes from each post’s stored answer to its answer under the proposed policy (or under the current policy when it has no stored answer). sampled_on counts sampled posts the threshold would newly hold for, sampled_off those it would stop holding for, and estimated the changes in the whole population, both ways, with a 95% interval widened on each side by the noise estimate. Here 11 of 200 sampled posts changed at hide, so the sample alone estimates 2,652 of the 48,210 posts. Before noise, that estimate’s interval is 1,497 to 4,615, and the noise estimate of 482 widens it to 1,015 to 5,097.
  • noise has the same fields, for the changes from each post’s stored answer to a new answer under the current policy. The engine can answer a little differently each time it judges the same post, and a write of the change judges the posts again, so about this many of its changes are noise. Here 2 of 200 posts changed at hide with no change to the policy. Compare noise with thresholds to see how much of the change is the policy. A threshold near many posts’ numbers has more noise (see which numbers move with noise).
  • A judgment with features reads its thresholds on the corrected p, so the simulation counts its changes on the corrected p too.
  • without_stored_answer counts the posts with no stored answer from the active version. Their changes compare the two new answers, and noise leaves them out.
  • examples names up to 20 sampled posts that changed, so you can read them yourself.
  • excluded counts the sampled posts the estimate leaves out. failed counts posts where either judging failed, including posts whose current policy is missing. out_of_scope counts posts that were gone when Brussle judged them.
  • fanout is what a write of the change would judge again, priced as a backfill of the posts in scope at the tiers your organization is in. Here that is 48,210 posts for $12.05. The rolling limit is 300,000 posts in 30 days, so unless other changes have used the window, none of it is deferred. Brussle defers work past the limit and never refuses it, and the deferred work catches up as the window has room (see the rolling limit).
  • larger_sample is set when an interval is too wide to decide, which means the sample’s interval, before noise, reaches more than 5% of the population either side. It is then the smallest sample, up to 1,000, that would decide, and you run the simulation again with that sample. Here each interval decides, so it is null. A larger sample does not make noise smaller.
A sample with no changes still gives an interval above zero (0 of 200 agrees with up to about 900 of 48,210). A sample of the whole population adds no uncertainty. Even then, the interval is one number only if the simulation also found no noise, and a write’s count can differ from the simulation’s by about the noise estimate. A simulation approves nothing and applies nothing. It changes no answer and keeps nothing for later. You do not have to simulate before a write, and you can write whatever the simulation said.

Write the change

Upsert the policy as you would any other document, and write no post.
A write that changes what the relation shows (here the rules) judges the posts again, while a write to another field of the policy judges nothing again. Under on_change, a burst of edits causes one fan-out after the policy has had no change for the debounce (10 minutes by default), and at least once an hour while it keeps changing. With the default debounce, give fresh_answer a longer timeout. Under on_read, the default policy, there is no fan-out, and a get or query of a post judges it again at once, against the policy as it is then. Posts in scope, created within freshness.fanout.scope.created_within (30 days by default) and matching its where, read pending from the moment Brussle acknowledges the write until they are judged again. They read stale (limit_reached) past the rolling limit, and catch up when the window has room. Older posts outside the scope keep their answers from the old policy and read stale (referenced_changed), with the change in referenced_changes on a get, until their next write. To bring older posts under the new policy, widen the scope with a PATCH before you write the change ({"freshness": {"fanout": {"scope": {"created_within": null}}}} covers every post), and simulate after it, so that population and fanout count the wider scope. See what the answers show.

Keep the review queue

The review queue holds the posts between review and hide. It asks for fresh answers only, so a post that is pending after a policy change, or stale outside the scope, stays out until its new answer lands. The same filter with hide true gives the list of posts to hide.
A subscription with the same filter tells you, by webhook or in the events feed, when a post enters or leaves the queue. Create it with ns.subscriptions.create(name="review-queue", filters=review_queue, events=["entered", "exited"]). It sees only settled answers, so a pending post sends nothing until its new answer lands, and each post that moves after a policy change gets its own event with cause: "fanout". The first check is silent, and one subscription.synced event says how many posts already matched. To keep a receiver correct, read events are edges, not states.

Record what moderators decide

A moderator who reverses a hidden post records that it did not break the policy, and one who upholds it records that it did. Turn those writes into outcomes with an outcome rule, or post them. From 50 outcomes with 15 of each kind, each answer carries a corrected number with a 95% interval, once the correction beats the engine’s numbers on held-out outcomes. From 100 with 20 of each, the threshold recommender (Team plan and above) suggests hide and review from them. A policy change is a write and makes no new version of the judgment, so one fit covers outcomes from before and after it. After a large change, though, the older outcomes describe the old rules.

Read what the engine saw

post_8812 links to paid content, which the new rule forbids, yet suppose its fresh answer says it breaks nothing. Open its evaluation:
GET /namespaces/{ns}/evaluations/{id} returns the same record, with the compiled context (the exact text the engine read).
  • related_documents lists each related document the engine read, with its relation, document_id and revision. Expect one entry: relation policy, document house_rules, at the revision your write made.
  • context_truncated: true means Brussle cut the context to fit max_tokens. It leaves out the whole policy before it cuts any of the post, so a long post can push the policy out, and then related_documents has no policy entry and context has no related.policy.
  • context_truncated: false with no policy entry means the post points at no policy, because its attributes.policy_id names no document, or names one whose kind is not policy.
An answer judged without the policy is fresh like any other (see a fresh answer can have incomplete inputs). To find such answers, filter on context_truncated in an export of evaluations, or watch stats.truncation_rate on ns.judgments.get("breaks_policy"), the share of today’s evaluations that Brussle cut. To fix them, raise max_tokens, which is a new version at a larger size class, or shorten the rules, which is a write of the policy that you simulate first.

Cost and limits

A simulation is free. Brussle does not bill its evaluations, and they write nothing. Each simulation uses one call from a daily allowance it shares with suggested parts, of 20 calls for each judgment and 50 for each organization, the two together. Past either, the route answers rate_limited with details.limit and details.resets_at (the next midnight UTC). See limits. Brussle bills a write of the change as any judging, for the posts the fan-out judges again at their size class. The simulation’s fanout gives that price before you write.