Performance: Auto-fixing malformed output
This concept affects the responsiveness and smoothness of user interactions by handling errors in output generation without blocking the interface.
Jump into concepts and practice - no test required
const response = await model.generate(input); let output; try { output = JSON.parse(response.text); } catch { output = autoFixMalformed(response.text); } // UI remains responsive with fallback
const response = await model.generate(input); const output = JSON.parse(response.text); // no error handling // If output is malformed, app crashes or blocks UI
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No error handling on malformed output | Minimal | 0 but blocks JS thread | High due to blocking | [X] Bad |
| Try-catch with auto-fix fallback | Minimal | 0 and non-blocking | Low, smooth rendering | [OK] Good |
output_parser = JsonOutputParser(auto_fix=True)
raw_output = '{"name": "Alice", "age": 30' # missing closing brace
fixed_output = output_parser.parse(raw_output)
print(fixed_output)output_parser = JsonOutputParser(auto_fix=True)
raw_output = '{"name": "Bob", "age": 25,,}'
fixed_output = output_parser.parse(raw_output)
print(fixed_output)