Fix LLM reasoning mismatches by validating title and strengthening prompt

Add title validation in mood router to detect when the LLM returns reasoning
for a different movie than the jellyfin_id it selected. Also add explicit
prompt instruction to double-check reasoning matches the selected movie.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 10:34:43 -07:00
parent 22cec43b51
commit 0ca43f1d13
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -83,6 +83,15 @@ async def get_mood_recommendations(request: Request, body: MoodRequest):
continue
movie = candidate_map[jf_id]
# Validate that the LLM's title matches the actual movie to catch mix-ups
rec_title = rec.get("title", "").strip().lower()
if rec_title and rec_title != movie.title.strip().lower():
logger.warning(
f"LLM title mismatch: returned '{rec.get('title')}' for jellyfin_id "
f"'{jf_id}' which is actually '{movie.title}' — skipping"
)
continue
recommendations.append(
Recommendation(
jellyfin_id=movie.jellyfin_id,
+1
View File
@@ -13,6 +13,7 @@ Rules:
- Rank by how well they match the described mood, not by rating alone
- If the mood mentions kids, children, or family, only recommend age-appropriate content (G, PG, or PG-13)
- Return exactly {max_results} recommendations, or fewer only if the library has very few matches
- IMPORTANT: Double-check that your reasoning accurately describes the specific movie you selected. The title, jellyfin_id, and reasoning MUST all refer to the same movie. Do not mix up details between different movies in the list.
Respond with ONLY valid JSON in this exact format, no other text:
{{