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 themoderation.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.
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
ns.judgments.create(body) (TypeScript) or ns.judgments.create(**body) (Python).
- It judges only posts (
kindpost), so the policy itself is never judged or billed. It reads each post’s title and text, and therulesof the document named inattributes.policy_idwhen itskindispolicy. - A post with no
policy_idis 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 thatidagain judges the posts again (see a missing referenced document). - Thresholds. Hide a post above
hide(0.9), and send the posts betweenreview(0.5) andhideto 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).
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
Withoutconfirm: 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, toPOST /v1/namespaces/acme%2Fforum/judgments/breaks_policy/simulate with the name of the relation that reads it:
relationmust be one of the judgment’s relations that reads one referenced document. Brussle does not simulate a named list, and anything else isinvalid_request.- The document must be one the write API would accept. Each image in its
imagesmust reference an image the namespace holds, and an image sent as a data URL isinvalid_image. sampleis 1 to 1,000, 200 by default.
202 with a simulation job and writes nothing. Read the job until its status is done or failed:
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:
populationis the number of posts a write of the change would judge again, andsampledhow many of them the simulation judged.thresholdshas 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_oncounts sampled posts the threshold would newly hold for,sampled_offthose it would stop holding for, andestimatedthe changes in the whole population, both ways, with a 95%intervalwidened on each side by thenoiseestimate. Here 11 of 200 sampled posts changed athide, 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.noisehas 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 athidewith no change to the policy. Comparenoisewiththresholdsto 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 correctedptoo. without_stored_answercounts the posts with no stored answer from the active version. Their changes compare the two new answers, andnoiseleaves them out.examplesnames up to 20 sampled posts that changed, so you can read them yourself.excludedcounts the sampled posts the estimate leaves out.failedcounts posts where either judging failed, including posts whose current policy is missing.out_of_scopecounts posts that were gone when Brussle judged them.fanoutis 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_sampleis 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 thatsample. Here each interval decides, so it isnull. A larger sample does not make noise smaller.
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.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 betweenreview 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.
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_documentslists each related document the engine read, with itsrelation,document_idandrevision. Expect one entry: relationpolicy, documenthouse_rules, at the revision your write made.context_truncated: truemeans Brussle cut the context to fitmax_tokens. It leaves out the whole policy before it cuts any of the post, so a long post can push the policy out, and thenrelated_documentshas nopolicyentry andcontexthas norelated.policy.context_truncated: falsewith nopolicyentry means the post points at no policy, because itsattributes.policy_idnames no document, or names one whosekindis notpolicy.
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 answersrate_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.