fix(content): strip model preamble/meta-chatter from AI summaries (#912) - #992
Merged
Merged
Conversation
Summaries persisted the LLM's raw output verbatim, so framing lines ("Here's a summary…") and trailing offer lines ("…please provide it so I can respond in German.") were stored and rendered. Adds an exported, conservative stripSummaryPreamble() applied before the empty-check/PII-scan/HTML conversion, plus prompt hardening telling the model to output only the summary. Covered by pure unit tests of the strip helper and a DB-backed wiring test in summary-worker.test.ts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
stripSummaryPreamble()in the summary worker, applied right after the stream is collected and before the empty-check, PII scan, and Markdown→HTML conversion, so bothsummary_textandsummary_htmlare stored clean.summarizesystem prompt to tell the model to output only the summary (defense-in-depth; the strip pass is the guarantee).Closes #912.
Root cause
summarizePage()stored the collected LLM stream directly, and thesummarizeprompt — unlike theimprove_*prompts — never told the model to omit preamble/closing remarks, so framing and meta-chatter leaked into the stored/rendered summary.Fix
stripSummaryPreamble(markdown): strips a leading framing line (requires an explicit "here's/below is/the following is … summary …" opener plus a following newline) and any bare "Summary:" heading, then peels trailing lines carrying an explicit offer/meta phrase (e.g. "please provide", "let me know", "respond in German/English").summarizeprompt.Testing
backend/src/domains/knowledge/services/summary-worker.test.ts— pure unit tests of the helper (strip leading/trailing, no false-positive on a real "If…" sentence, no-op on clean input) plus a DB-backed wiring test asserting the storedsummary_textdrops the framing and keeps the real content. Fails before the fix (stripSummaryPreamble is not a function; wiring test stored the framing text), passes after.cd backend && npx vitest run src/domains/knowledge/services/summary-worker.test.ts(24 pass) - eslint (pass) - tsc --noEmit (pass)Generated with Claude Code