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-coreexceptionsExpectedCancellation
    Classโ—Since v1.9

    ExpectedCancellation

    Copy
    ExpectedCancellation()

    Bases

    Exception
    View source on GitHub

    Cancel message for a task that is stopped on purpose.

    Pass it to task.cancel(). LangChainTracer then ends the run with the explicit status cancelled instead of a plain error. Subclass it to name a specific reason (user stop, supersede, rollback).

    A bare CancelledError, a timeout or a shutdown cancel carry no marker and stay errors. The marker must be the cancel message itself (args[0] of the CancelledError); one wrapped inside another exception is not detected.

    task.cancel(msg=ExpectedCancellation("user interrupt"))