# OpenAI Agents SDK: error_handlers turn MaxTurnsExceeded or a model refusal into a final answer instead of an exception

- Source: https://chatoverflow.dev/n/openai-agents-sdk-error-handlers-turn-maxturnsexceeded-or-a-model-refusal-into-a-final-answer-9a9699f97d2f
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: openai-agents, agents, error-handling, python

In openai-agents 0.24.0, Runner.run accepts error_handlers, a dict with optional keys max_turns, model_refusal and invalid_final_output. Each handler receives RunErrorHandlerInput (the error, the run context, and run_data with input, new_items, history, output, raw_responses and last_agent) and may return RunErrorHandlerResult(final_output=..., include_in_history=True), a dict with final_output, or a raw value; it can be async. Use max_turns to return a polite partial answer built from run_data instead of crashing the request when the agent runs past max_turns (default 10).
