Skip to content

fix(audit): keep AI recommendations to page facts and 150-character copy - #1132

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/audit-recommendation-facts
Oct 17, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/audit-recommendation-facts

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Site Audit recommendations no longer invent facts, and their copy stays under 150 characters per sentence. This is SA-001 of the Site Audit v2 spec.

The bug: a pricing-page audit suggested "Join brands like TechFlow, which saw a 34% increase in 'Recommended' citations…" and Product schema with guessed prices. If a customer pasted that onto their site, it would publish false claims under their brand.

Prompt (server/src/lib/audit/recommendations.js)

  • Facts: use only facts from the page text or the brand data. Never invent customers, testimonials, case studies, statistics, percentages, prices, dates, awards or quotes. Use [customer name], [real metric], [price], [date] or [source URL] instead.
  • Brand data: the brand's name, description and domains. It is sent only when the audited URL is on one of the brand's domains, so an audit of a competitor's page never borrows this brand's facts (brandFactsFor, host.js onBrandDomain).
  • Length:
    • The explanation is one imperative sentence of at most 150 characters.
    • Every draft sentence is at most 150 characters.
    • The meta-description draft asks for 120–150 characters, which is inside the signal's 80–160 range.
  • Markup: JSON-LD/HTML moves to a new code field. It is exempt from the length rule but uses the same placeholders.

Validator (server/src/lib/audit/recommendation-guard.js)

The output is checked before it is saved.

  • Facts. Numbers, percentages, prices, dates and company names that don't appear in the known facts become placeholders.
    • Known facts: the page text, title, meta tags, JSON-LD, today's date (given to the model) and the brand data.
    • Company names: CamelCase names, and capitalised names after "brands like", "trusted by" and similar.
    • Units count: a percentage or price must be one on the page; the bare number isn't enough.
  • Left alone:
    • URLs and existing placeholders.
    • The AI engines and platforms the product is about (ChatGPT, Google, Perplexity, Wikipedia…), AI crawler names and schema.org types.
    • In the explanation only: writing instructions ("a 120–150 character description", "3–5 questions") and score targets.
    • List numbering ("1.", "Step 2").
    • In JSON-LD, structural numbers ("position": 1). A bare JSON number becomes a quoted placeholder, so the code stays valid JSON.
  • Length. Over-long items get one rewrite; only the parts over the limit are replaced. Anything still too long is cut at a word boundary with "…", and a link is never cut in half.
  • Monitoring. One log line per audit counts what was changed: facts, items too long, rewritten, cut.

Report (web/src/components/audit/audit-report.tsx)

  • Placeholders are highlighted in the paste-able copy.
  • Code has its own block and copy button.
  • Under copy that holds placeholders, a note says: "Replace placeholders in [brackets] with your real data before publishing."
  • Older audits, without code, render as before.

Not changed

  • Signal scoring and the 47-signal set.
  • Existing audits.

Known limit

The validator checks what the spec lists: numbers, percentages, prices, dates and company names. Invented people, quotes and awards (e.g. "Written by Jane Smith") are forbidden by the prompt but not caught by the validator.

Related issue

None. Site Audit v2 spec, task SA-001.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Run an audit of a page on the brand's own domain, e.g. a pricing page. The local install has no model or Scrape.do key, so this needs a configured environment.
    • The recommendations should contain no customer, percentage, price or date that isn't on the page; placeholders appear instead.
    • Every explanation and draft sentence should be ≤ 150 characters.
  2. Open the report.
    • Placeholders are highlighted, with the note under them.
    • The FAQ recommendation shows its JSON-LD in a separate "Copy code" block.
  3. Run an audit of another site's page: the brand's name and description aren't sent to the model.
  4. Check the server log for [audit] recommendation guard changed the model output with the counts.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint and npm test (1473) pass.
    • recommendation-guard.test.js:
      • the spec's TechFlow/34% example;
      • unknown vs known prices and percentages;
      • names and lists of names;
      • instruction numbers and numbering;
      • dates, ISO datetimes and year-shaped counts;
      • URLs;
      • JSON-LD that stays valid;
      • length checks and cuts, including links.
    • recommendations.test.js:
      • the prompt rules and brand data;
      • the guard on model output;
      • one rewrite, matched by position, that keeps parts within the limit;
      • the cut when the rewrite fails or is still long;
      • brandFactsFor for own vs other sites.
    • host.test.js: onBrandDomain.
  • web: yarn test (1252) and yarn build pass. audit-report.test.tsx covers the highlighting, the code block and the note.
  • Browser: an audit row on the demo brand, with recommendations produced by running a model-like answer (invented customer, %, hours and a 2024 JSON-LD date) through the validator.
    • Checked at 1440px and 1024px, in light and dark.
    • The row was deleted afterwards.
  • Not run: a live model run, because the local install has no model key. @gkhngyk, could you run one audit on a configured environment?

🤖 Generated with Claude Code

Site Audit recommendations could invent customers, percentages and prices
(e.g. "Join brands like TechFlow, which saw a 34% increase…"), which a user
might paste onto their site as false claims.

- The prompt now allows only facts from the page or the brand data (name,
  description, domains — sent only for pages on the brand's own domains)
  and asks for [placeholders] otherwise, a one-sentence explanation of at
  most 150 characters and draft sentences of at most 150 characters.
- JSON-LD/HTML moves to its own `code` field, exempt from the length rule.
- recommendation-guard.js checks the output before saving: numbers,
  percentages, prices, dates and company names the page and brand data
  don't contain become placeholders; over-long items get one rewrite, then
  a cut at a word boundary. Counts are logged per audit.
- The report highlights placeholders, shows code in its own copy block and
  notes "Replace placeholders in [brackets] with your real data before
  publishing."

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This is SA-001 from the Site Audit v2 spec: recommendations keep to page and brand facts (placeholders otherwise) and to 150 characters per sentence. The local install has no model or Scrape.do key, so it's covered by unit tests and a sample audit row only. Could you run one live audit of a pricing page on a configured environment and check the recommendations and the [audit] recommendation guard log line? Thanks!

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebuilt on main: server tests (recommendation guard, recommendations, host), the audit report tests, typecheck, lint and format pass, and CI is green.

The rewrite of over-long items is one batched call per audit, and a failed rewrite falls back to the word-boundary cut, so it can't block an audit from completing. Brand facts reach the prompt only for pages on the brand's own domains (onBrandDomain), so a competitor page's recommendations can't borrow the brand's name or description.

@gkhngyk
gkhngyk merged commit 393dc6a into ansvisor:main Oct 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants