ModelRefusalError(
self,
message: str = 'Model refused to produce the requested output',
*,
raw_message: BaseMessage | None = | Name | Type | Description |
|---|---|---|
message | str | Default: 'Model refused to produce the requested output' |
raw_message | BaseMessage | None | Default: None |
| Name | Type |
|---|---|
| message | str |
| raw_message | BaseMessage | None |
Exception raised when a model declines to produce the requested output.
Providers report a refusal as a successful response rather than an HTTP error
(for example Anthropic's stop_reason="refusal", or the refusal field in
OpenAI Structured Outputs), so a plain model call returns the message as-is.
Integrations raise this exception from paths that need the content the model
withheld, such as with_structured_output, so callers can handle refusals the
same way across providers instead of receiving a parsing error.
Retrying the same request is unlikely to succeed.
Error message.
The model response that contained the refusal. Its
content_blocks hold the refusal block, including any
provider-specific details in extras.
Create a ModelRefusalError from a standard refusal block.