You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/running_agents.md
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -410,7 +410,7 @@ Set the hook per run via `run_config` to redact sensitive data, trim long histor
410
410
411
411
### Error handlers
412
412
413
-
All `Runner` entry points accept `error_handlers`, a dict keyed by error kind. Today, the supported key is`"max_turns"`. Use it when you want to return a controlled final output instead of raising `MaxTurnsExceeded`.
413
+
All `Runner` entry points accept `error_handlers`, a dict keyed by error kind. The supported keys are`"max_turns"` and `"model_refusal"`. Use them when you want to return a controlled final output instead of raising `MaxTurnsExceeded` or `ModelRefusalError`.
414
414
415
415
```python
416
416
from agents import (
@@ -441,6 +441,38 @@ print(result.final_output)
441
441
442
442
Set `include_in_history=False` when you do not want the fallback output appended to conversation history.
443
443
444
+
Use `"model_refusal"` when a model refusal should produce an application-specific fallback instead of ending the run with `ModelRefusalError`.
445
+
446
+
```python
447
+
from pydantic import BaseModel
448
+
449
+
from agents import Agent, ModelRefusalError, RunErrorHandlerInput, Runner
0 commit comments