Back to The Perch

Developer series, part 3

Facts your rules can use

In part 1, the refund call sent refund_amount as a fact and we moved on. Some values belong in the input your function runs with, and others belong in facts a rule can compare. Get the split right and your governance engineer can write the rules they need without reading your code.

Two arguments with different jobs

Here's the refund call again, with the refund facts from the demo.

const result = await veriproof.govern(
  'support.issue_refund',
  { ticketId, orderId: order.id, amount, currency: 'USD' },
  ({ input, invocationId }) =>
    billing.refund({ ...input, idempotencyKey: invocationId }),
  {
    facts: {
      refund_amount: amount,
      order_total: order.total,
      days_since_delivery: order.deliveredDaysAgo,
      return_window_days: 30,
    },
    review: { profile: 'support_refund_approval' },
  },
);

The input is the refund itself, shaped the way your billing code wants it. You should be free to refactor that shape without breaking anyone's rule. Facts are the promise you make to rules. VeriProof puts them at input.snapshot.facts, so a return-window check could read like this:

past_return_window if {
	facts := input.snapshot.facts
	facts.days_since_delivery > facts.return_window_days
}

It helps to know who sees which.

  • Your function gets the input, as you passed it or as a rule transformed it. Facts never reach it.
  • Rules read facts by name. They can see the input too, but a rule written against your input's shape breaks the day you rename a property.
  • Reviewers see facts. The manager's card shows each single-value fact as a labeled value, or the review.facts you pass instead. The input stays in your application.
  • The record keeps facts with every decision, after your organization's sensitive data policy masks anything it matches. The input is recorded only if you turn on content capture.

Why not let a rule read the chat? Daniel typed "the $900 I paid," and a rule could try to fish a number out of that, but your order system already knows the answer. A fact carries the value your code trusts, with a type and a name a person can read, and it doesn't change when a customer phrases things differently.

Name facts the way the business talks

Your governance engineer thinks in refunds and return windows, so name facts that way.

  • Use snake_case business terms. The review card builds each label from the key, so days_since_delivery shows up as "Days since delivery." A camelCase key comes through as one run-together word.
  • Put the unit in the name. Nobody will read return_window_days as hours. For money, send the currency alongside the amount.
  • Send the context along with the trigger. With return_window_days in the facts, the rule compares against whatever window your system uses, so changing the window doesn't mean changing the rule. order_total sits next to refund_amount even when they match, because partial refunds are where they differ.
  • Use a fixed set of strings for categories. A return_reason of "damaged" or "not_as_described" is much easier to write a rule against than free text, and you can list the allowed values when you confirm the field.

If you work in a regulated industry, the SDK ships generated vocabularies, from banking to telecom, with their allowed values already defined. Build a value with Industry.fact() and pass it as the industry option, and rules read it under input.snapshot.industry. Industry.fact() throws on a value the catalog doesn't permit, so a typo fails in your code instead of slipping past a rule.

If every call sends the same kind of facts, register a factExtractor on the client once. Facts passed on a call win over extracted ones.

const veriproof = Veriproof.fromEnv(process.env, {
  factExtractor: ({ actionName, input }) =>
    actionName === 'support.issue_refund' ? refundFacts(input) : undefined,
});

How your facts look from the portal

Once your agent has recorded some activity, the governance engineer can pick your facts in the condition editor. It keeps fields a Developer has confirmed under Application data, and anything VeriProof has seen in activity but nobody has described yet under Sent by the application, not yet confirmed.

An observed fact is enough to draft and test a rule. Activation waits until a Developer or Administrator confirms what it means, because a value showing up in activity can't explain itself.

You confirm fields under Application data in the application's Policy tab. Select Review field on a suggestion from activity and fill in What does this field mean?. Check the data type, and add allowed values if it's a category. Select Required by the application only if every valid record includes the field. Then select Save field contract.

Every save creates a new contract version, and the SDK checks calls against it. If a call breaks the contract, say a string where you promised a number, govern() returns failed with reason code policy_contract_invalid and the refund doesn't run. The same view flags a field that's Confirmed, not yet found in activity or whose Recorded type does not match.

When a rule needs a fact you don't send

Say your governance engineer wants a second rule: the agent can't refund more than what's left on the order. That needs already_refunded, and the chat agent doesn't send it yet.

They don't have to wait for you to start. In the condition editor they type "Already refunded," choose Add "Already refunded" as needed application data, and save and test the draft. Readiness then flags the missing field, and Request application data, then Send request, hands you the work. VeriProof sends one request to the application's responsible Developer, or links the rule to a request that's already open.

The request describes each field with an example and names the step it's blocking. You won't touch any Rego. Here's your side, from Inbox:

  1. Claim request, so the team can see who's on it.
  2. Review application data opens the application data view with the requested fields selected.
  3. Add already_refunded to your facts and confirm the field there. Then send a test session.
  4. Submit for review. Once the fields are confirmed, the governance engineer gets a Policy data is ready item and reruns the rule's tests.

If the agent already sends the field and it only needs a meaning, it's shorter still. VeriProof closes the request as soon as every field is confirmed.

Once a rule is enforced in Production, a fact that keeps going missing or arrives as the wrong type gets you one request. A single stray miss doesn't.

What content capture adds

By default, the record holds the decision and your facts, but not the refund's input or what your function returned. So facts are what a reviewer or auditor reads later.

Setting captureContent: true asks VeriProof to keep the input and the released output as well. Your organization has to allow it with the Content capture switch in Settings → Organization controls. If the call asks and the organization doesn't allow it, govern() returns failed with content_capture_not_permitted before the refund starts.

The sensitive data policy masks matches before anything is captured, and the input and output are each capped at 65,536 bytes of UTF-8. The demo turns capture on, along with two options that are recorded whether you capture content or not:

import type { GovernOptions } from '@veriproof/sdk-core';
 
const options: GovernOptions = {
  facts: refundFacts(order),
  sessionContext: {
    displayName: `${customer.name} asks for a $${amount} refund`,
    externalReference: order.id,
  },
  workflowFacts: {
    initiatorId: `support-chat:${customer.id}`,
    initiatorDisplayName: customer.name,
  },
  captureContent: true,
};

sessionContext names the session so people can find it by order number. workflowFacts records who started the work, and can carry a plain-language businessContext for whoever reviews it. Keep the values a rule compares in facts.

Turn capture on when someone really needs to read the text and your data policy allows storing it. The content capture guide has the details, and Policy data covers field contracts end to end.

Earlier and later in the series

Part 2, When a person steps in, covers reviews done properly. Part 4, The check inside your framework, moves the check into your framework's adapter and shows where it hands back to core govern().

See facts decide a real case

See how VeriProof checks each action against your rules before it runs, or try one yourself in a simulator.