Repository navigation
fix(opportunities): prevent prompt index leak in generated titles/descriptions (#424) - #442
Merged
gkhngyk merged 1 commit intoJul 16, 2026
Merged
Conversation
…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
approved these changes
Jul 16, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anddescriptions (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 modelcan return a
relatedPromptIndexto link each opportunity back to theright
prompt_id. Nothing told the model these indexes existed onlyfor that field, so it occasionally leaked them into the prose.
Fix
Two-layer defense in both generation paths
(
content-worker.jsandopportunity-generator.js), as the issuerecommends — with
generateObject, models weight per-field schemadescriptions 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 bothtitleanddescriptionfields (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.jshad no.describe()ontitleordescriptionat all before this PR — both fields were barez.string()with no guidance, which made the leak more likely in that path.
What was NOT changed
relatedPromptIndexfield and its resolution logic are untouched inboth files — opportunities still link to the correct
prompt_idare generated in the brand's language, so index-mention patterns vary
too much to strip safely)
status='new'opportunities and regenerates)Acceptance criteria
relatedPromptIndexresolution is untouched