Skip to content

Fix: make auto book-language actually steer insight output#76

Merged
vitofico merged 1 commit into
mainfrom
fix/insight-language-adherence
May 31, 2026
Merged

Fix: make auto book-language actually steer insight output#76
vitofico merged 1 commit into
mainfrom
fix/insight-language-adherence

Conversation

@vitofico

Copy link
Copy Markdown
Owner

Problem

You reported that auto book-language wasn't working — insights still came out in English for non-English books.

Root cause: the book language does reach the server (verified end-to-end for library EPUBs), but the v6 directive was too weak — a single line referencing an ISO code, buried at the end of an all-English prompt:

Respond in the language identified by ISO 639-1 code "it".

Weak / structured-output models ignore that and default to English.

Fix (single-pass, no extra model call)

  • Name the languageItalian (ISO 639-1: it), not just "it".
  • Lead with it — the directive is now the first instruction (models over-weight the opening), with a short reminder repeated at the end.
  • Scope it — write the PROSE fields in the target language (intro, analysis, theme_analysis text, craft_notes, distinctive_take, discussion_prompts, content_warnings, author bio), but keep controlled fields exactly as-is: themes (controlled English tags), confidence, and proper names (titles, author/series names). This is critical — a naive "write everything in X" would translate the controlled themes vocabulary and break validation.
  • PROMPT_VERSION 6 → 7 (cache-bust).

Expected reliability

~70–85% on a weak self-hosted model (the test default hints at a Llama-class backend), higher on a stronger model. If your deployment's model still won't comply after this, the follow-up is a conditional prose-only translation-repair pass (only fires when the output is detectably not in the target language) — deliberately not included here to avoid a dependency + an extra model call against the daily budget unless it's actually needed.

Tests

353 server unit tests pass (new coverage: named-language directive, field-scoping that protects controlled fields, directive-leads-prompt) + AI integration suite; ruff clean. Pure prompt output also verified directly.

Not covered (separate, smaller gaps)

OPDS catalog books and the no-OPF fallback send no language at all, so auto can't resolve for them — pre-existing, tracked separately.

The v6 language directive was a single weak line referencing an ISO *code*
(`Respond in the language identified by ISO 639-1 code "it"`) buried at the
end of an all-English prompt. Weak/structured-output models ignored it and
wrote English anyway — so "auto follows the book's language" didn't visibly
work.

Strengthen it (single-pass, no extra model call):
- Name the language ("Italian (ISO 639-1: it)"), not just the code.
- Lead the prompt with the directive instead of burying it; repeat a short
  reminder at the end.
- Scope it explicitly: write the PROSE fields (intro, analysis, theme_analysis
  text, craft_notes, distinctive_take, discussion_prompts, content_warnings,
  author bio) in the target language, but keep the controlled fields exactly
  as-is — `themes` (controlled English tags), `confidence`, and proper names
  (titles, author/series names). This prevents the model from translating the
  controlled vocabulary and breaking validation.

Bump PROMPT_VERSION 6 -> 7 (materially changes output; cache-bust). Tests
updated to assert the named-language, field-scoped directive.
@vitofico
vitofico merged commit 6237074 into main May 31, 2026
13 checks passed
@vitofico
vitofico deleted the fix/insight-language-adherence branch May 31, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant