LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    Chat LangChain

    What can I help with?

    Enter to send·Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coreexceptionsModelRefusalError
    Class●Since v1.7

    ModelRefusalError

    Copy
    ModelRefusalError(
      self,
      message: str = 'Model refused to produce the requested output',
      *,
      raw_message: BaseMessage | None = 

    Bases

    ModelError

    Constructors

    Attributes

    Methods

    Inherited fromModelError

    Attributes

    Ais_retryable: bool
    —

    Whether retrying the same model request may succeed.

    View source on GitHub
    None
    )

    Parameters

    NameTypeDescription
    messagestr
    Default:'Model refused to produce the requested output'
    raw_messageBaseMessage | None
    Default:None
    constructor
    __init__
    NameType
    messagestr
    raw_messageBaseMessage | None
    attribute
    raw_message: raw_message
    method
    from_refusal

    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.