Skip to content

fix(opportunities): prevent prompt index leak in generated titles/descriptions (#424) - #442

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:fix/prompt-index-leak-in-opportunities
Jul 16, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:fix/prompt-index-leak-in-opportunities

Conversation

@Maqbool61

Copy link
Copy Markdown
Contributor

Summary

Closes #424

Fixes a bug where the LLM occasionally used internal bracketed prompt
indexes like [0] or "Prompt 3" in user-facing opportunity titles and
descriptions (e.g. "For Prompt [0] specifically, there is 32,880 monthly
AI volume..."
). Users reading the opportunity card have no idea what
Prompt [0] means — it's a pure internal artifact.

Root Cause

Both generation paths label the prompt list with [${i}] so the model
can return a relatedPromptIndex to link each opportunity back to the
right prompt_id. Nothing told the model these indexes existed only
for that field, so it occasionally leaked them into the prose.

Fix

Two-layer defense in both generation paths
(content-worker.js and opportunity-generator.js), as the issue
recommends — with generateObject, models weight per-field schema
descriptions heavily, and the system-prompt rule alone doesn't reliably
stop the leak:

1. System prompt rule (new bullet in both files):

The bracketed [N] indexes in the prompt data exist ONLY for the
relatedPromptIndex field. NEVER mention an index like "[0]" or
"Prompt 3" in titles or descriptions — refer to the prompt by
quoting or paraphrasing its actual text/topic instead.

2. Hardened Zod schema .describe() on both title and description
fields (both files):

Never reference prompts by their bracketed index like [0] or "Prompt 3"
— name the topic or paraphrase the prompt text instead.

Note: opportunity-generator.js had no .describe() on title or
description at all before this PR — both fields were bare z.string()
with no guidance, which made the leak more likely in that path.

What was NOT changed

  • relatedPromptIndex field and its resolution logic are untouched in
    both files — opportunities still link to the correct prompt_id
  • No regex post-processing was added (rejected per issue: descriptions
    are generated in the brand's language, so index-mention patterns vary
    too much to strip safely)
  • Existing bad rows self-heal on the next worker run (the worker deletes
    status='new' opportunities and regenerates)

Acceptance criteria

  • ✅ Both generation paths carry the new rules
  • ✅ relatedPromptIndex resolution is untouched
  • ✅ Prettier, ESLint, and all 115 tests pass

…criptions

Closes #424

The LLM occasionally used the bracketed [N] prompt indexes in user-facing
opportunity titles/descriptions (e.g. 'For Prompt [0] specifically...').
The index exists only for relatedPromptIndex resolution and should never
appear in prose.

Fix applied to both generation paths:

content-worker.js:
- Added rule to OPPORTUNITY_SYSTEM_PROMPT: [N] indexes exist ONLY for
  relatedPromptIndex; never mention them in titles or descriptions
- Hardened title .describe() to explicitly prohibit index references
- Hardened description .describe() with the same prohibition

opportunity-generator.js:
- Added the same rule to SYSTEM_PROMPT
- Added .describe() to title and description schema fields with the
  same prohibition (previously had no .describe() at all)

Stating the rule in both the system prompt and per-field schema
descriptions matters: with generateObject, models weight per-field
schema descriptions heavily, and the system-prompt rule alone does
not reliably stop the leak.

Signed-off-by: Maqbool Ahmed <[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.

Covers both generation paths with the two-layer defense from #424, and extending the guard to the title fields was the right call. LGTM — the real-world check is the first content run after deploy, which will also regenerate the existing polluted 'new' opportunities.

@gkhngyk
gkhngyk merged commit ba89a84 into ansvisor:main Jul 16, 2026
4 checks passed
@Maqbool61
Maqbool61 deleted the fix/prompt-index-leak-in-opportunities branch July 16, 2026 10:51
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.

Content opportunity descriptions leak internal prompt indexes like "Prompt [0]"

2 participants