Fail the Save on an Empty Completion, Not a Green Toast
Description and use
Problem: an empty LLM completion is treated as a successful save, causing a misleading green toast. Solution: validate completion text, reject empty/truncated results, return a ‘failed’ status with reason, and display that reason in the UI.
Problem
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.
Outcome
Implemented a contract that treats empty completions as failures, preventing misleading success indicators and ensuring data integrity.
Workflow
- 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
Evidence
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.
- Record date: 2026-10-09T12:41:04.112Z