Skip to main content

Voice Citation Pipeline

The problem: voice has no inline markers​

The chat channel's citation extractor assumes the LLM's answer contains inline [1], [2], [3] markers that map to the retrieved chunks. The extractor pattern-matches these markers, deduplicates the referenced sources, and stores them with the conversation message.

The voice system prompt explicitly strips inline citation markers — they are un-speakable. A text-to-speech system reading "De cardiologie is bereikbaar via ingang B [1]." produces audible gibberish: "…via ingang B bracket one bracket." The voice system prompt therefore instructs the LLM to never include [N] markers in the answer.

This created a silent cascade failure affecting every voice turn:

  1. The voice answer contains no [N] markers.
  2. The marker extractor therefore returns an empty list.
  3. The deduplication step sees the empty list and returns an empty list.
  4. The cache write stores the empty list for the cache key.
  5. The stored message ends up with no citations.
  6. The diagnostic view finds no per-dimension scores (its schema validation fails) and silently falls back to the older rendering.

Nothing in this cascade raised an exception. Every function behaved correctly for its stated inputs. The failure was architectural: the chat path's assumption (markers exist) propagated into the voice path without a guard.

This is a textbook silent-failure branch (the project's silent-failure discipline): a code path that "fails quietly" with an empty fallback. The fix required a regression test that asserts that a voice turn has a non-empty citation list, not just "no exception."

The cascade in detail​

Three steps each assumed markers were present:

StepAssumptionEffect when no markers
Citation extractionParses [N] from answer textReturns an empty list
Citation deduplicationDeduplicates by marker referenceReturns an empty list on empty input
Citation cache writeWrites the answer and its citations to the query cacheWrites an empty list; future cache hits on the same query return no citations

The diagnostic's downstream failure (empty dimensional scores) was not the root cause — it was the symptom that surfaced the citation pipeline bug in the first place. The diagnostic's LLM call was returning a valid JSON object with per-dimension scores; the cache read was overriding it with the stale empty citation lists from the broken voice turns that had already poisoned the cache.

The fix — three changes​

Voice fallback at finalisation. When the channel is voice and the marker extractor returns nothing, citations are now derived directly from the retrieved chunks that were passed to the LLM (up to five, using each chunk's source and title).

Skip deduplication when there are no markers. Chunk-derived citations have no duplicate marker structure, so the dedup step is skipped cleanly.

Cleanup and logging. A log line records the citation count per voice turn immediately before the cache write, so a count of 0 is a visible signal rather than a silent empty write.

Cache flush discipline​

After any change to the citation pipeline, flush the semantic query cache.

The cache stores the answer, citations and diagnostic scores per query. Stale entries from before the fix contain no citations; they would serve incorrect results on cache hits until they expire or are flushed. Voice-channel entries can be flushed on their own, which is the safer option on a live pilot. Do not rely on time-based expiry for a citation-pipeline change: the expiry window can be several hours, and stale entries would affect all traffic during that window.

Diagnostic view — downstream consequence​

The v2 diagnostic response renders per-dimension scores (relevance, safety, citation quality, etc.) in individual cards. It calls a separate LLM completion with JSON output enforced. Before the citation fix, this LLM call was succeeding, but the stale empty citations from the cache were making the response schema validation fail, causing the diagnostic to silently fall back to the older rendering with no dimensional scores.

After the fix:

  1. Voice turns write chunk-derived citations (non-empty)
  2. Cache stores non-empty citations
  3. v2 diagnostic reads non-empty citations
  4. Schema validation passes
  5. Per-dimension cards render correctly

References​

  • The post-mortem, with conversation identifiers, is kept in the project's private repository.
  • The project's silent-failure discipline (log the fallback, and test that the result is non-empty rather than only that nothing raised) motivated the regression test requirement.