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
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
  • 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
  • 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 Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coreloadload
Function●Since v0.3

load

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.

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.

Copy
load<T>(text: string, options: LoadOptions): Promise<T>

Parameters

NameTypeDescription
text*string

The JSON string to parse and load.

optionsLoadOptions

Options for loading. See LoadOptions for security guidance.

Example

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

// Basic usage - secrets must be provided explicitly
const msg = await load<AIMessage>(jsonString);

// With secrets from a map (preferred over secretsFromEnv)
const msg = await load<AIMessage>(jsonString, {
  secretsMap: { OPENAI_API_KEY: "sk-..." }
});

// Allow loading secrets from environment — ONLY for fully trusted data
const msg = await load<AIMessage>(jsonString, {
  secretsFromEnv: true
});
View source on GitHub