Repository navigation
Description
HealthLog version
1.49.1
Deployment type
Self-hosted (Docker)
What happened?
On /insights, with the app language set to Polish, the daily briefing under the greeting displayed a raw ---KEYVALUES--- block after the summary paragraph. Both markers and the rows between them appeared as part of the visible briefing text.
A sanitized example of the layout:
Dzień dobry
Krótki akapit z podsumowaniem dnia.
---KEYVALUES---
Kroki: 4200 [kroków/dzień] (ostatnie 7 dni)
Zapisy snu: 5 [zapisów] (ostatnie 7 dni)
---END---
Expected behavior
The greeting should display the briefing paragraph without the internal markers or the rows between them. Previously cached briefings containing the block should also display cleanly.
The Polish safety contract marks ground_rule_2_evidence_block_sentinel as surface: coach. The rule tells the model to append a ---KEYVALUES--- block after its prose. However, the native Insights prompt builder assembles its rules from all of GROUND_RULE_KEYS, so the Coach instruction also reaches the Insights model. The same builder serves other native locales, so the prompt issue may extend beyond Polish.
Polish safety contract
HealthLog/src/lib/ai/prompts/safety-contracts.pl.yaml
Lines 22 to 33 in 1a7cf2d
| ground_rule_2_evidence_block_sentinel: | |
| parser_critical: true | |
| surface: coach | |
| locale: | | |
| Kluczowe liczby trafiają do bloku dowodów na końcu odpowiedzi, | |
| ujętego w znaczniki ---KEYVALUES--- oraz ---END---. Format | |
| każdej linii: "<label>: <value> [<unit>] (<window>)". Twardy | |
| limit 8 linii. Znaczniki to dosłowne markery, które parser | |
| czyta — proszę ich nigdy nie tłumaczyć. | |
| must_contain: | |
| - "---KEYVALUES---" | |
| - "---END---" |
Native Insights prompt builder
HealthLog/src/lib/ai/prompts/native-prompts.ts
Lines 397 to 401 in 1a7cf2d
| /** | |
| * The full Insights ground-rule order. All 14 matrix rules apply — the | |
| * Insights prompt is a superset of the Coach contract. | |
| */ | |
| const INSIGHTS_GROUND_RULE_ORDER: GroundRuleKey[] = [...GROUND_RULE_KEYS]; |
If the model puts the block inside the dailyBriefing.paragraph JSON string, the response can still pass schema validation. The Insights hero then renders that field directly. Coach replies go through parseKeyValuesSentinel, which strips the block from the visible prose.
Briefing validation
HealthLog/src/lib/ai/briefing-blocks.ts
Lines 125 to 145 in 1a7cf2d
| if (issues.length > 0) return { state: "invalid", issues }; | |
| const parsed = dailyBriefingSchema.safeParse({ | |
| ...block, | |
| signalsOfDay, | |
| keyFindings, | |
| }); | |
| if (!parsed.success) { | |
| return { | |
| state: "invalid", | |
| issues: parsed.error.issues.map( | |
| (issue) => | |
| `dailyBriefing.${issue.path.map(String).join(".")}: ${issue.message}`, | |
| ), | |
| }; | |
| } | |
| return { | |
| state: "valid", | |
| briefing: { ...block, ...parsed.data } as DailyBriefing, | |
| repairs, | |
| }; |
Insights hero
HealthLog/src/components/insights/hero-strip.tsx
Lines 128 to 135 in 1a7cf2d
| user?.timezone ?? DEFAULT_TIMEZONE, | |
| ); | |
| const greetingKey = resolveGreetingKey(greetingHour); | |
| const greetingBase = t(greetingKey); | |
| const greeting = userName ? `${greetingBase}, ${userName}` : greetingBase; | |
| const subtitle = briefing?.paragraph ?? t("insights.heroFallbackSubtitle"); | |
| // v1.22 — calendar-bucketed freshness label ("Updated today, HH:MM" / | |
| // "yesterday" / "on DD.MM."), matching the briefing + per-metric cards so the |
Coach parser
HealthLog/src/lib/ai/coach/keyvalues.ts
Lines 169 to 193 in 1a7cf2d
| * Split a raw assistant reply into `{ prose, keyValues }`. | |
| * | |
| * The streamed prose passed to the client is the `prose` field — the | |
| * `---KEYVALUES---` block is stripped before any token frame is sent | |
| * so the user never sees the raw sentinel. | |
| */ | |
| export function parseKeyValuesSentinel(raw: string): SentinelParseResult { | |
| if (!raw) { | |
| return { prose: "", keyValues: [], malformed: false, malformedEntries: [] }; | |
| } | |
| const openIdx = raw.indexOf(OPEN_SENTINEL); | |
| if (openIdx === -1) { | |
| return { | |
| prose: raw, | |
| keyValues: [], | |
| malformed: false, | |
| malformedEntries: [], | |
| }; | |
| } | |
| // Everything before the opening marker is prose; trim trailing | |
| // whitespace introduced by the marker's own leading newline so the | |
| // bubble doesn't render an extra blank paragraph. | |
| const prose = raw.slice(0, openIdx).replace(/\s+$/u, ""); |
Steps to reproduce
The issue was observed on a generated briefing. Reproduction may depend on the model output. A deterministic regression test can use a dailyBriefing.paragraph fixture containing the block shown above.
Error ID
No response
Support info / support report
Screenshots / other logs
Browser / OS (if applicable)
No response
Pre-flight checks
- I confirmed this is not a duplicate of an existing issue.
- I redacted any secrets, tokens, or personal data from logs.
Activity
test(insights): read sources through the shared helpers in the sentin…
MBombeck commentedon Dec 1, 2026
Thanks a lot @ferges123, this was a really precise analysis. You were right on every point, and the links saved me a good amount of digging.
What was going on: the Insights prompt for French, Spanish, Italian and Polish picked up every rule from the shared safety list, including the Coach's rule to add a block of figures after its answer. So it was not only Polish. English and German have their own prompts and never carried that rule.
The fix in #1764 works at both ends:
Your example layout is now a regression test.
Once the PR is merged it will be on
:edge, and it ships in the release this Saturday, December 5.Refs #1761