Fail the Save on an Empty Completion, Not a Green Toast
Описание и применение
Проблема: пустой ответ от модели считается успешным сохранением, что приводит к ложному зеленому уведомлению. Решение: проверять текст завершения, отклонять пустые/обрезанные ответы, возвращать статус «failed» и показывать причину в UI.
Задача
An empty completion from an LLM provider is treated as a successful save, leading to a green toast in the UI even though no text was stored.
Результат
Implemented a contract that treats empty completions as failures, preventing misleading success indicators and ensuring data integrity.
Рабочий процесс
- Receive save request from UI
- Call LLM provider for completion
- Check completion text and finish_reason
- If empty or truncated, mark invoice as failed and return status 'failed' with reason
- If valid, persist notes and return status 'saved'
- UI reads JSON status and shows draft or success accordingly
Доказательства
An empty completion is a failed user action, even when the free server stayed up and the model call did not throw.
The UI may render a spinner, the API may speak JSON, and the provider may speak a schema you do not own.
I keep the draft visible and show the reason beside the notes field, so the clicker can see that nothing was stored.
- Дата записи: 2026-10-09T12:41:04.112Z