Skip to content

fix: handle gemini language prediction behaviour#75

Merged
JamesMcMinn merged 4 commits into
mainfrom
investigate-duplicate-languages-in-pas-dropdown-ai-2211
Jul 8, 2026
Merged

fix: handle gemini language prediction behaviour#75
JamesMcMinn merged 4 commits into
mainfrom
investigate-duplicate-languages-in-pas-dropdown-ai-2211

Conversation

@JamesMcMinn

Copy link
Copy Markdown
Contributor

Fixes https://linear.app/fullfact/issue/AI-2211/investigate-duplicate-languages-in-pas-dropdown

Essentially, what I found when investigating was that Gemini will often not return the 2 letter ISO code for a language, but instead the 3 letter code or even sometimes the full name of the language.

This PR attempts to fix these cases in the database, and normalise the values returned by Gemini to prevent non-2 letter iso codes from making it into the database going froward.

I've tested this on a copy of the prod DB locally and it seemed to go fine with no migration issues. We might hit a few minutes of slowdown when we deploy this but I don't think that's avoidable.

There's an argument that perhaps we should instead use something like langid for this but that's a slightly bigger change.

@JamesMcMinn
JamesMcMinn requested a review from dearden July 6, 2026 10:54

@dearden dearden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a sensible fix, and very well spotted on the error - I can imagine that was a faff to discover.

@JamesMcMinn
JamesMcMinn merged commit 4ebe4ff into main Jul 8, 2026
3 checks passed
JamesMcMinn added a commit that referenced this pull request Jul 15, 2026
Restores the language prediction fix that was merged (PR #75) and then
reverted (PR #76). The DB language-code normalization migration (21) is
excluded here and will be run manually against production; app.py keeps
MIGRATION_TARGET_VERSION at 20 so nothing is auto-run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants