Skip to content

fix(cloro): read names instead of ChatGPT entity tags in answers - #1097

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/entity-markup-in-answers
Oct 16, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/entity-markup-in-answers

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

ChatGPT answers from Cloro (chatgpt-web) can contain entity tags where a name should be, for example <Entity category="software" value="Tesseract" disambig="Adlift AI search optimization platform"/>. This was seen on app.ansvisor.com on 2026-10-16, on the prompt "What is the most comprehensive list of software for AI search engine optimization?" (ChatGPT run of Oct 16, 05:15 GMT+3).

  • Display: the answer's Markdown renderer prints raw HTML as text, so the AI RESPONSE showed the literal tags.
  • Metrics: response-parser.js matched names inside the tag attributes:
    • A competitor named only in a disambig was counted as mentioned.
    • A competitor called "Software" matched category="software".
    • The extra names shifted mention_position and mentioned_entity_count. In one sample answer the brand ranked 4th instead of 2nd.

Changes:

  • Ingest: new server/src/lib/entity-markup.js (stripEntityMarkup) replaces each self-closing <Entity … value="X" …/> with X, unescaping XML escapes in the value. A tag without a value is left as is. parseScraperResponse applies it to every engine's text, so new answers are stored clean. Sentiment, reports, improve evidence and opportunity generation then all read the names.
  • Parser: mentions, competitor counts and positions are now matched on tag-free text (matchableText). Recounting stored answers therefore gives the right numbers too.
  • Web: web/src/lib/entity-markup.ts mirrors the helper. It is used by ResponseDetail (prompt page run rows and the result page) and by the report mention excerpt, so answers stored before this fix also read properly.

Existing production rows are not rewritten here. They display correctly through the web change, but their stored mention counts and positions still come from the raw text. A backfill to recount them (and clean response) would be a separate PR.

Related issue

None. The problem was seen in production on 2026-10-16.

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. cd server && npm test: entity-markup.test.js, plus the new cases in response-parser.test.js (disambig/category attributes are not counted, ranks follow the visible names) and cloro-scraper.test.js (stored text is clean).
  2. cd web && yarn test: src/lib/entity-markup.test.ts.
  3. In a local dev DB, insert a chatgpt-web prompt_results row for a demo prompt whose response contains tags, e.g. **<Entity category="company" value="Acme Coffee" disambig="specialty coffee roaster"/>** — ….
  4. Open the prompt page (/dashboard/prompts/<id>), expand the ChatGPT group and open that run's response. Then open its full page (/dashboard/insights/<result id>). Both should show "Acme Coffee", not the tag. On main the tag shows as literal text.

Checked locally in light and dark themes and at 1024px.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web: yarn test (726 tests) and yarn build.
  • server: npm run format, npm run lint and npm test (1204 tests).
  • Root: npm run version:check fails, but it fails on main too (docker-compose images 0.2.0 vs 0.3.0) and is unrelated to this change.

🤖 Generated with Claude Code

ChatGPT answers from Cloro can carry tags such as
<Entity category="software" value="Tesseract" disambig="..."/> where the
name should be. They showed as literal text on the answer, and their
attributes counted as mentions: a competitor named only in disambig was
counted, and the extra names shifted mention positions.

- Clean the tags to their value when a Cloro result is parsed, so new
  answers are stored clean.
- Match names on tag-free text in the response parser, so recounting
  stored answers gives the right numbers.
- Clean stored answers when they are shown and in report excerpts.

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

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

Thanks, approving. Merged onto main with #1098, #1091, #1092 and #1087, server tests pass (1278) and web tests pass (832). On production 612 of the last 30 days' 46,351 ChatGPT answers carry the tags (since Oct 9), plus 83 ChatGPT Shopping answers; no other engine has any. Their stored mention counts and positions still need the recount you mention, as a separate PR.

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