Skip to content

[Bug] Insights daily briefing renders raw ---KEYVALUES--- block #1761

Backlog

Description

@ferges123

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

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
/**
* 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

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
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
* 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

  1. added
    bug
    on Dec 1, 2026
  2. MBombeck commented on Dec 1, 2026

    @MBombeck
    Owner

    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:

    • Each prompt now only gets the rules meant for it, so the briefing model is no longer asked for the block at all. A new test checks this for every language and keeps the Coach prompt as it was.
    • The server now strips any such block (closed or left open) from the text the model wrote, using the same parser the Coach uses. That happens before a briefing is stored and again when one is served, so a briefing cached before the update shows up clean too, without a regenerate.

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions