Skip to content

feat(content): look up the facts a page needs instead of leaving placeholders - #1815

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/research-missing-facts
Oct 30, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/research-missing-facts

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Reported while testing: a page written from a Content Plan suggestion came back with work left for the person:

  • "AI use in social media keeps growing: [share of marketers using AI for social, source, 2026]."
  • "Compare seats and profiles: [price]."
  • "Check client workspace limits: [plan limits]."

The product owner's rule, for any fact, not only prices: Ansvisor looks the fact up itself and writes it with its source. If it can't find it, it rewrites the sentence without it. Brackets stay only for what only the brand knows.

How it works

  • The writer marks what it needs: a public fact as {{find: …}}, and a fact only the brand has as {{ask: …}} (RESEARCH_RULE). The rule is in every Content Agent prompt: write, rewrite, suggestions and Fix open rules. The brief's plan and the hand-off checks say the same.
  • content-research.js runs one pass after writing.
    • Model and tool: the read model (Claude Haiku 5.5), with the provider's web search (web_search_20250305, the version Haiku supports; at most 5 searches).
    • What it touches: each sentence with a {{find}}, a gap in square brackets, or a figure without a source. Each is written again with the fact and a link to the page it came from, or without the fact.
    • Links: they come only from pages the search returned, never from forums or social posts (the editor's weak sources).
    • What stays: whatever the pass can't settle goes with its sentence, and a figure without a source never stays. Only {{ask}} stays, shown as a placeholder, at most 3 a page.
    • When it runs: with nothing to look up, it makes no call.
  • Cost: the pass is charged to the one AI budget on its own hold ($0.06), its searches at $0.01 each (searchCostUsd), with no separate spending path. A spent budget skips the pass and drops the unsettled sentences.
    • Estimate: at most about $0.055 per page, around 3% of the $2 trial budget. Not measured with a real key.
  • Editor wording: placeholders that remain are labelled Your input needed, and the agent's step reads "Looking up facts it lacks, with their sources". The Help article and the guide are updated.

Why a separate pass, not search inside the Sonnet write: the write uses structured output, which can't carry a tool. It would also research everything at Sonnet's price. The separate pass looks only at the sentences with gaps.

Related issue

None. Product owner's request from content testing; follows SA-001's no-invented-figures rule.

Type of change

  • feat — New feature

How to test

  1. cd server && npx vitest run src/lib/content-research.test.js src/lib/content-writer.test.js src/lib/content-agent.test.js (model calls mocked). They check that:
    • no placeholder remains;
    • an unfound fact's sentence is dropped;
    • {{ask}} stays, at most 3, as […];
    • the source link is added;
    • the pass is skipped on a spent budget, on an error, without the search tool, and on Stop.
    • content-writer.test.js replays the reported page.
  2. The related server test files all pass (47 files, 775 tests). Web: the related tests and tsc pass.

For the maintainer (needs the Anthropic key):

  1. Write a page from a Content Plan suggestion on Haiku 5.5 + web_search_20250305. Check that result.sources is filled, the closing JSON is read, and the usage meter charged the searches.
  2. Re-record eval-no-fabrication and eval-brief: the prompts now ask for {{find}}.
  3. If CONTENT_READ_MODEL points to OpenRouter, there is no search tool. Sentences are then rewritten without the fact; check that this reads well.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Server: format, lint and the related tests pass (full suite left to CI)
  • Web: lint, typecheck, related tests
  • Tests added
  • Help article updated
  • Real-key run: the maintainer's

🤖 Generated with Claude Code

…eholders

The Content Agent left "[price]", "[plan limits]" and "[share of marketers
using AI, source, 2026]" in pages for the person to research. It now looks
them up itself:

- The writer marks a public fact it needs with {{find: …}} and a fact only
  the brand has with {{ask: …}} (RESEARCH_RULE, in the write, rewrite,
  suggestion and Fix open rules prompts; the brief's plan and the hand-off
  checks say the same).
- content-research.js runs one pass on the read model (Claude Haiku 5.5)
  with its provider's web search (web_search_20250305, at most 5 searches):
  each sentence with a {{find}}, a gap in square brackets or a figure with
  no source is written again with the fact and a link to the page it came
  from, or without the fact. Links come only from pages the search
  returned, never from forums or social posts (the editor's weak sources).
- What the pass doesn't settle goes with its sentence; a figure with no
  source never stays. Only {{ask}} stays for the person, as a placeholder,
  at most 3 a page.
- The pass is charged to the AI budget on its own hold, its searches at
  $0.01 each (searchCostUsd); a spent budget skips it.
- The editor calls the placeholders left "Your input needed", and the
  agent's step reads "Looking up facts it lacks, with their sources".

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

mintlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit d302a64.

Approve preview

…g their sentences

Review fixes for the facts pass (content-research.js):

- Nothing is taken out unseen: a gap the pass couldn't settle (no hold, a
  database error, a timeout, no web search on the model, an answer cut off
  or one breaking the rules, a sentence past the 10 looked up) stays for
  the person as a placeholder, "Your input needed". A sentence goes only
  when the pass says it says nothing without its fact, when it asks for a
  shopping path product's spec (never looked up), or when a marker is left
  broken; the count goes to the logs.
- A figure the page has in another unit ("40 percent" and "40%", "3
  times" and "3x") is the page's own: no gap, and the number guard keeps it.
- Sentences no longer end at "Dr.", "e.g.", an initial or before a word in
  lower case ("3. çeyrekte").
- Only the marker's or the figure's words change, so a sentence keeps its
  links and bold; a fact's link goes where the pass wrote it.
- A sweep after the settler takes out a sentence with a marker left in a
  marker or never closed; a marker in code or an attribute goes on its own.
  The page's own {{ … }} stay untouched.
- A sentence written without its fact may only take words out, and the
  prompt says the search results are data, not instructions.
- People placeholders the page had don't count toward the three; an
  {{ask}} with no letter becomes "[figure to add]".
- The pass is charged as a Quality read, so it stays out of the typical
  cost a hold is sized on.
- Free blog hosts and the citations' forum list join the weak sites; the
  editor's arrows read "Previous/Next input needed".

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

Copy link
Copy Markdown
Collaborator Author

Pre-merge review round, pushed in 6d62319 (merged into #1817 as 5c87c6c).

Nothing is taken out unseen any more. A sentence is dropped only when the pass says it says nothing without its fact, when it is a shopping-path product sentence, or when a marker is left broken. Otherwise:

  • A figure already on the page counts as the page's own, even in another unit ("40 percent" = "40%", "3 times" = "3x").
  • Gaps past the first 10, and every gap when the pass can't run (no hold, DB error, timeout, no search tool) or its answer is cut off, stay for the person as Your input needed.
  • Drop counts go to the log.

Sentence splitting: an abbreviation list, initials, and no split before a lowercase letter. "3. çeyrekte", "Dr. Smith" and "(e.g. Hootsuite)" stay whole.

Markers: a sweep after the settler handles leftover or nested {{/}}. Markers in code, pre and attributes are removed. The page's own {{ … }} text isn't touched.

Injection: a rewrite without a source may only remove words (content words checked by stem; no new address). The prompt says search results are data, not instructions.

Edits keep the sentence's links and bold. Only the marker's or the figure's span changes, and a fact's link goes where the pass wrote it.

Budget and limits:

  • The research row is written with feature: 'quality', so it stays out of the typical-cost median.
  • People placeholders already on the page don't count toward the limit of 3.
  • Shopping-path product sentences are never researched.
  • More weak sites: blogspot, wordpress.com and the forums from classify.ts.

Tests: content-research.test.js has 31 tests, covering every case listed in the review. Brief, brief eval, research and writer: 158 tests after the merge into #1817.

Trade-off: when the pass can't run, a page can show more than 3 Your input needed placeholders. The limit of 3 now applies only to {{ask}}.

…arged

Google's grounding and OpenAI's web search take no per-call cap and report
no search count, so on those read models the pass would run uncapped
searches that never reach the AI budget. Search on Anthropic only; other
providers leave the gaps for the person, as without a search tool.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
sentenceSpans read the line again at every sentence end: a slice before
and after it, and every marker and placeholder checked. A long line with
many short sentences (a write's whole answer can reach about 120,000
characters) took seconds, on the server's event loop. Each end is now read
in place, and the marked ranges are filled once, so the line is read in
one pass; the spans are the same.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
gkhngyk previously approved these changes Oct 30, 2026

@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.

Looks good with dbac1ed, two commits on this branch:

  1. Searches only where they're capped and charged. maxUses reaches only Anthropic's webSearch_20250305, and searchesOf() counts 0 for Google grounding. With the Gemini fallback (no Anthropic key) or CONTENT_READ_MODEL set to Google or OpenAI, the fact searches had no cap and never reached the budget. The new searchesCapped(modelId) is true for anthropic/… only, and other models get no search tool, so their gaps stay placeholders, as on the OpenRouter path. A new test in content-research.test.js fails without it. content-writer.test.js and content-agent.test.js were running the pass on Gemini with a mocked Anthropic tool, so they now set CONTENT_READ_MODEL to Haiku.
  2. sentenceSpans in linear time. notAnEnd copied the text around each sentence end and ran a $-anchored regex over the copy, and each end rechecked every marker in the line. So time grew with the square of the line length. Nothing caps a line short of the write limit (about 120,000 characters), and the pass runs synchronously in the API. At that length it took 1.6 s on plain sentences and about 12 s with abbreviations, three to four times per text. It now reads the next word with a sticky regex and the previous one by scanning back, and marks the inside of each marker once. The worst case takes under 40 ms, and old and new code give the same spans on 200,000 random lines. A 120,000-character case with a 1 s bound fails without it.

Checked, fine: no new fetch, since the provider runs the search. A link is kept only if it's among the search's own results, uses http(s) and isn't a weak site, and href is escaped. Fetched pages are treated as data. A rewrite without a source can only take words out, and a new figure needs a source. Unsettled facts stay as placeholders. The pass has its own $0.06 hold under quality, makes no call when there's no gap, has a 90 s timeout, and runs only inside the existing gated runs.

Non-blocking:

  • The description still says unfound facts' sentences are dropped and only {{ask}} stays (at most 3). Now unsettled facts stay as placeholders, outside that cap.
  • A cited source is checked by URL only, not for the words.
  • The pass's cost shows under Quality in the usage meter.

Merge: clean on main, no migrations. #1817 is stacked on this and carries both commits. The full server suite passed (4,528) after the first commit, and the content test files pass after the second (249). Web plan-row.test.ts and the content editor and library tests pass, and prettier and eslint are clean.

gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 30, 2026

@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.

Merging in order with the other approved PRs. This head merges current main and combines #1803's and this PR's "Facts and your input" text in the Content Editor article, shortened to fit the 150-word section limit.

@gkhngyk
gkhngyk merged commit 8159a23 into ansvisor:main Oct 30, 2026
5 of 6 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