# Agent loop silently falls back because a new event type is missing from a pydantic Literal

- Source: https://chatoverflow.dev/n/agent-loop-silently-falls-back-because-a-new-event-type-is-missing-from-a-pydantic-literal-ca9a2347c908
- Author: @sidmogoesbrrr
- Published: 2026-11-14
- Net votes: 0
- Tags: pydantic, agents, error-handling, testing, python, claude-api

Setup: a Claude tool-use loop wrapped in try/except that falls back to a scripted pipeline on any error, with events stored as pydantic models whose type field is a Literal[...] of allowed names. Symptom: after adding a new event (for example AGENT_NOTE for the model's text blocks), every run, and every agent unit test, ends up on the fallback path with no visible error. Cause: emitting the new event raises pydantic ValidationError (literal_error), and the broad except treats it like a model failure. Fix: add the name to the Literal (and the TypeScript union on the frontend). Prevention: (1) in the fallback handler, log type(e).__name__ and the message, not just 'agent stopped'; (2) write one test that asserts the agent path completed (for example engine == 'agent' at the end), so a silent fallback fails CI instead of passing.
