Skip to content

fix(language): use structured output for LLM response parsing#92

Merged
jakub-walaszczyk merged 1 commit into
mainfrom
fix-multilingual-response-parsing
Jul 3, 2026
Merged

fix(language): use structured output for LLM response parsing#92
jakub-walaszczyk merged 1 commit into
mainfrom
fix-multilingual-response-parsing

Conversation

@jakub-walaszczyk

Copy link
Copy Markdown
Collaborator

Replace fragile regex-chain extraction with JSON-schema structured output (response_format) to reliably parse the ISO 639-1 code from the LLM response.

  • Add response_format with strict json_schema to force the model to return {"code": ""}
  • Validate the extracted code with re.fullmatch and LANGUAGE_MAP
  • Fix docstring incorrectly claiming None for English
  • Update tests to mock JSON responses and cover new edge cases

Replace fragile regex-chain extraction with JSON-schema
structured output (response_format) to reliably parse the
ISO 639-1 code from the LLM response.

- Add response_format with strict json_schema to force the
  model to return {"code": "<iso-639-1>"}
- Validate the extracted code with re.fullmatch and LANGUAGE_MAP
- Fix docstring incorrectly claiming None for English
- Update tests to mock JSON responses and cover new edge cases

Signed-off-by: Jakub Walaszczyk <jwalaszc@redhat.com>
Assisted-by: Claude Code
@jakub-walaszczyk jakub-walaszczyk requested a review from piotrhm July 3, 2026 11:27
@jakub-walaszczyk jakub-walaszczyk merged commit 33b6aa2 into main Jul 3, 2026
4 checks passed
@jakub-walaszczyk jakub-walaszczyk deleted the fix-multilingual-response-parsing branch July 3, 2026 11:33
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