rudra-js

verify

import { verify } from '@rudra-js/attested';

Call verify to check a piece of copy against the facts you supply, before a shopper sees it.

verify(text: string, facts: Facts) => VerifyResult

Reference

verify(text, facts)

Parameters

  • text: The copy to check, exactly as the shopper will see it.
  • facts: What you stand behind.
    • values: Every number the copy may use, such as the price and the rating. Write each one the way your own system does, such as 39, '$1,299.00' or '4,8'. Every number inside a value counts, so 'ships 13 March' supplies 13.
    • bannedPhrasesoptional: Phrases to catch on top of the built-in list, such as 'nur noch'. The built-in list is English only.
    • allowedPhrasesoptional: Wording you stand behind, such as 'free shipping' for a shop that offers it. A listed phrase that sits inside one of yours isn't reported there. The same words elsewhere in the copy still are.

Returns

A VerifyResult. Its supported is true only when both checks pass. quantity holds the report of the number check, and wording the report of the word list. Each report has its own supported and a list of findings, one for each token that failed. A finding holds the token and a reason you can log. Each report's checked counts the numbers it found, or the phrases it looked for.

Caveats

  • The number check is proof. The wording check is a word list, so copy can be reworded around it. When quantity.supported is true, every number written in digits is one you supplied. "A trail shoe at half the price" gets past the word list, though "half price" is on it. Each report's strength says which kind it is: 'proof' or 'best-effort'.
  • The number check proves the number came from you. It doesn't prove the sentence uses it right. With a price of 39 in values, "39 sold in the last hour" passes too.
  • A number written as a word isn't checked. "Only two left" has no numeral, so quantity.checked is 0 and the copy passes.
  • A number the check can't read fails, such as ½ or the 4K in "4K display".
  • Put in values only numbers you're happy to see anywhere in the copy. A SKU of AT-2199 lets "Was $2,199" pass. Take them from fields you write, never from a title a marketplace seller wrote.
  • Check the text exactly as you render it. Only ½ left passes. A page that decodes it shows the shopper "Only ½ left", which the check would have caught.

Usage

Checking a line of copy before you show it

Core already checks every word the model writes for the block. Call verify on copy from anywhere else, such as your own templates or another model.

import { verify } from '@rudra-js/attested';

const shoe = { title: 'Switchback Trail Shoe GTX', price: 174, rating: 4.8 };

export function headlineFor(written: string): string {
  const result = verify(written, { values: [shoe.price, shoe.rating, 5] });
  if (result.supported) return written;

  for (const finding of [...result.quantity.findings, ...result.wording.findings]) {
    console.warn(finding.reason);
  }
  return shoe.title;
}

The facts are the price, the rating and the 5 it is out of. "Rated 4.8 out of 5, for $174" passes. "Only 2 left at $174" fails, because nothing you supplied holds a 2.

When the copy fails, show words you wrote yourself, such as the product title. Log each reason so you can see what was caught.

For more on choosing facts, see Checking the wording yourself.

Troubleshooting

A true sentence fails because of a number in it

Every number in the copy has to be in values, even one that makes no claim. "Machine wash at 30°C" fails until you supply 30. The same goes for a size, a year or a phone number.

Add the number to values, or keep it out of the copy.

Wording you stand behind is caught

The word list catches "free shipping" even when your shop offers it. It also finds "sale" in "There is no sale on this product".

Pass the wording in allowedPhrases, such as 'no sale'. Keep each one tight. It clears every listed phrase inside it, including phrases a later release adds to the list.