LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Llms
  • Profile
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coreerrorsContextOverflowError
Class●Since v1.1

ContextOverflowError

Error class representing a context window overflow in a language model operation.

This error is thrown when the combined input to a language model (such as prompt tokens, historical messages, and/or instructions) exceeds the maximum context window or token limit that the model can process in a single request. Most models have defined upper limits for the number of tokens or characters allowed in a context, and exceeding this limit will prevent the operation from proceeding.

The ContextOverflowError extends the LangChainError base class with the marker "context-overflow".

Copy
class ContextOverflowError

Bases

LangChainError<this>
  • Use this error to programmatically identify cases where a user request, prompt, or input sequence is too long to be handled by the target model.
  • Model providers and framework integrations should throw this error if they detect a request cannot be processed due to its size.

Example

Copy
try {
  await model.invoke(veryLongInput);
} catch (err) {
  if (ContextOverflowError.isInstance(err)) {
    // Handle overflow, e.g., prompt user to shorten input or truncate text
    console.warn("Model context overflow:", err.message);
  } else {
    throw err;
  }
}

Constructors

constructor
constructor

Properties

property
cause: Error

The underlying error that caused this ContextOverflowError, if any.

This property is optionally set when wrapping a lower-level error using ContextOverflowError.fromError. It allows error handlers to access or inspect the original error that led to the context overflow.

property
message: string
property
name: "ContextOverflowError"
property
stack: string
property
isInstance: IsInstanceFn
property
stackTraceLimit: number

Methods

method
captureStackTrace
method
fromError→ ContextOverflowError

Creates a new ContextOverflowError instance from an existing error.

This static utility copies the message from the provided error and attaches the original error as the ContextOverflowError.cause property, enabling error handlers to inspect or propagate the original failure.

method
prepareStackTrace

Inherited fromLangChainError

Properties

Pcause: Error
—

The underlying error that caused this ContextOverflowError, if any.

Pmessage: StoredMessagePname: stringPstackPisInstance: IsInstanceFnPstackTraceLimit

Methods

McaptureStackTraceMprepareStackTrace
View source on GitHub