LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • 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
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coreload
Module●Since v0.3

load

Functions

Interfaces

View source on GitHub
function
load→ Promise<T>

Load a LangChain object from a JSON string.

WARNING — insecure deserialization risk. This function instantiates classes and invokes constructors based on the contents of text. If text originates from an untrusted source, an attacker can craft a payload that instantiates arbitrary allowed classes with attacker-controlled arguments, potentially causing secret exfiltration, SSRF, or other side effects.

A serialized payload should be treated as executable configuration — it can configure models with custom endpoints, headers, or other constructor kwargs that execute during instantiation.

Only call load() on data you have produced yourself or received from a fully trusted origin (e.g., your own database). Never deserialize user-supplied or network-received JSON without independent validation.

interface
LoadOptions

Options for loading serialized LangChain objects.

Load LangChain objects from JSON strings or objects.

WARNING: load() deserializes data by instantiating classes and invoking constructors. Never call load() on untrusted or user-supplied input. Doing so can lead to insecure deserialization — including arbitrary class instantiation, secret exfiltration, and server-side request forgery (SSRF). Only deserialize data that originates from a trusted source you control.

How it works

Each Serializable LangChain object has a unique identifier (its "class path"), which is a list of strings representing the module path and class name. For example:

  • AIMessage -> ["langchain_core", "messages", "ai", "AIMessage"]
  • ChatPromptTemplate -> ["langchain_core", "prompts", "chat", "ChatPromptTemplate"]

When deserializing, the class path is validated against supported namespaces.

Threat model

A serialized LangChain payload crosses a trust boundary because the manifest may contain serialized objects and configuration that affect runtime behavior. For example, a payload can configure a chat model with a custom base_url, custom headers, a different model name, or other constructor arguments. These are supported features, but they also mean the payload contents should be treated as executable configuration rather than plain text.

Concretely, deserialization instantiates classes, so any constructor on an allowed class will run during load(). A crafted payload that is allowed to reach an unintended class — or an intended class with attacker-controlled kwargs — could cause network calls, file operations, or environment-variable access while the object is being built.

Security model

The secretsFromEnv parameter controls whether secrets can be loaded from environment variables:

  • false (default): Secrets must be provided in secretsMap. If a secret is not found, null is returned instead of loading from environment variables.
  • true: If a secret is not found in secretsMap, it will be loaded from environment variables. Use this only in trusted environments.

Hardening recommendations

  • Never enable secretsFromEnv unless the serialized data is fully trusted. A crafted payload can reference arbitrary environment variable names, leaking secrets to an attacker-controlled class constructor.
  • Keep secretsMap minimal. Only include the specific secrets the serialized object actually needs.
  • Keep importMap / optionalImportsMap as small and static as possible. Each entry widens the set of classes an attacker can instantiate. Never populate these maps from user input.

Injection protection (escape-based)

During serialization, plain objects that contain an 'lc' key are escaped by wrapping them: {"__lc_escaped__": {...}}. During deserialization, escaped objects are unwrapped and returned as plain objects, NOT instantiated as LC objects.

This is an allowlist approach: only objects explicitly produced by Serializable.toJSON() (which are NOT escaped) are treated as LC objects; everything else is user data.

Copy
import { ... } from "@langchain/core/load";