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/coreutilstypes
Module●Since v1.0

utils/types

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

Functions

function
extendInteropZodObject→ InteropZodObject

Extends a Zod object schema with additional fields, supporting both Zod v3 and v4.

function
getInteropZodDefaultGetter→ () => InferInteropZodOutput<T> | undefined

Returns a getter function for the default value of a Zod schema, if one is defined. Supports both Zod v3 and v4 schemas. If the schema has a default value, the returned function will return that value when called. If no default is defined, returns undefined.

function
getInteropZodObjectShape→ InteropZodObjectShape<T>

Retrieves the shape (fields) of a Zod object schema, supporting both Zod v3 and v4.

function
getSchemaDescription→ string | undefined

Retrieves the description from a schema definition (v3, v4, or plain object), if available.

function
interopParse→ T

Parses the input using the provided Zod schema (v3 or v4) and returns the parsed value. Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.

function
interopParseAsync→ Promise<T>

Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns the parsed value. Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.

function
interopSafeParse→ InteropZodSafeParseResult<T>

Safely parses the input using the provided Zod schema (v3 or v4) and returns a result object indicating success or failure. This function is compatible with both Zod v3 and v4 schemas.

function
interopSafeParseAsync→ Promise<InteropZodSafeParseResult<T>>

Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns a safe parse result. This function handles both Zod v3 and v4 schemas, returning a result object indicating success or failure.

function
interopZodObjectMakeFieldsOptional→ InteropZodObject

Creates a modified version of a Zod object schema where fields matching a predicate are made optional. Supports both Zod v3 and v4 schemas and preserves the original schema version.

function
interopZodObjectPartial→ InteropZodObject

Returns a partial version of a Zod object schema, making all fields optional. Supports both Zod v3 and v4.

function
interopZodObjectPassthrough→ InteropZodObject

Returns a passthrough version of a Zod object schema, allowing unknown keys. Supports both Zod v3 and v4 object schemas. If recursive is true, applies passthrough recursively to all nested object schemas and arrays of object schemas.

function
interopZodObjectStrict→ InteropZodObject

Returns a strict version of a Zod object schema, disallowing unknown keys. Supports both Zod v3 and v4 object schemas. If recursive is true, applies strictness recursively to all nested object schemas and arrays of object schemas.

function
interopZodTransformInputSchema→ InteropZodType

Returns the input type of a Zod transform schema, for both v3 and v4. If the schema is not a transform, returns undefined. If recursive is true, recursively processes nested object schemas and arrays of object schemas.

function
isInteropZodError→ boolean
function
isInteropZodLiteral→ obj is InteropZodLiteral

Determines if the provided value is an InteropZodLiteral (Zod v3 or v4 literal schema).

function
isInteropZodObject→ obj is InteropZodObject

Determines if the provided value is an InteropZodObject (Zod v3 or v4 object schema).

function
isInteropZodSchema→ input is InteropZodType<any, any>

Given either a Zod schema, or plain object, determine if the input is a Zod schema.

function
isShapelessZodSchema→ boolean

Determines if the provided Zod schema is "shapeless". A shapeless schema is one that does not define any object shape, such as ZodString, ZodNumber, ZodBoolean, ZodAny, etc. For ZodObject, it must have no shape keys to be considered shapeless. ZodRecord schemas are considered shapeless since they define dynamic key-value mappings without fixed keys.

function
isSimpleStringZodSchema→ schema is InteropZodType<string | undefined, string | undefined>

Determines if the provided Zod schema should be treated as a simple string schema that maps to DynamicTool. This aligns with the type-level constraint of InteropZodType<string | undefined> which only matches basic string schemas. If the provided schema is just z.string(), we can make the determination that the tool is just a generic string tool that doesn't require any input validation.

This function only returns true for basic ZodString schemas, including:

  • Basic string schemas (z.string())
  • String schemas with validations (z.string().min(1), z.string().email(), etc.)

This function returns false for everything else, including:

  • String schemas with defaults (z.string().default("value"))
  • Branded string schemas (z.string().brand<"UserId">())
  • String schemas with catch operations (z.string().catch("default"))
  • Optional/nullable string schemas (z.string().optional())
  • Transformed schemas (z.string().transform() or z.object().transform())
  • Object or record schemas, even if they're empty
  • Any other schema type
function
isZodArrayV4→ obj is $ZodArray<$ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>
function
isZodLiteralV3→ obj is ZodLiteral<unknown>
function
isZodLiteralV4→ obj is $ZodLiteral<Literal>
function
isZodNullableV4→ obj is $ZodNullable<$ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>
function
isZodObjectV3→ obj is ZodObjectV3
function
isZodObjectV4→ obj is $ZodObject<Readonly<Readonly<__type>>, $ZodObjectConfig>
function
isZodOptionalV4→ obj is $ZodOptional<$ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>
function
isZodSchema→ schema is ZodType<RunOutput, ZodTypeDef, RunOutput>

Backward compatible isZodSchema for Zod 3

function
isZodSchemaV3→ schema is ZodType<unknown, ZodTypeDef, unknown>
function
isZodSchemaV4→ schema is $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

Type Aliases

typeAlias
ChainValues: Record<string, any>
typeAlias
InferInteropZodInput: T extends z3.ZodType<unknown, z3.ZodTypeDef, Input> ? Input : T extends z4.$ZodType<unknown, Input> ? Input : T extends __type ? Input : never
typeAlias
InferInteropZodOutput: T extends z3.ZodType<Output, z3.ZodTypeDef, unknown> ? Output : T extends z4.$ZodType<Output, unknown> ? Output : T extends __type ? Output : never
typeAlias
InputValues: Record<K, any>
typeAlias
InteropZodDefault: T extends z3.ZodTypeAny ? ZodDefaultV3<T> : T extends z4.SomeType ? ZodDefaultV4<T> : never
typeAlias
InteropZodIssue: z3.ZodIssue | z4.$ZodIssue
typeAlias
InteropZodLiteral: z3.ZodLiteral<unknown> | z4.$ZodLiteral
typeAlias
InteropZodObject: ZodObjectV3 | ZodObjectV4 | ZodObjectV4Classic | ZodObjectMain
typeAlias
InteropZodObjectShape: T extends z3.ZodObject<Shape> ? { [K in keyof Shape]: Shape[K] } : T extends z4.$ZodObject<Shape> ? { [K in keyof Shape]: Shape[K] } : T extends z4Classic.ZodObject<Shape> ? { [K in keyof Shape]: Shape[K] } : T extends zodMain.ZodObject<Shape> ? { [K in keyof Shape]: Shape[K] } : never
typeAlias
InteropZodOptional: T extends z3.ZodTypeAny ? ZodOptionalV3<T> : T extends z4.SomeType ? ZodOptionalV4<T> : never
typeAlias
InteropZodType: z3.ZodType<Output, z3.ZodTypeDef, Input> | z4.$ZodType<Output, Input>
typeAlias
Mutable: { [P in keyof T]: T[P] }
typeAlias
PartialValues: Record<K, string | ()
typeAlias
StringWithAutocomplete: T | string & Record<never, never>

Represents a string value with autocompleted, but not required, suggestions.

typeAlias
ZodDefaultV3: z3.ZodDefault<T>
typeAlias
ZodDefaultV4: z4.$ZodDefault<T>
typeAlias
ZodNullableV4: z4.$ZodNullable<T>
typeAlias
ZodObjectMain: zodMain.ZodObject<any, any>
typeAlias
ZodObjectV3: z3.ZodObject<any, any, any, any, any>
typeAlias
ZodObjectV4: z4.$ZodObject
typeAlias
ZodObjectV4Classic: z4Classic.ZodObject<any, any>
typeAlias
ZodOptionalV3: z3.ZodOptional<T>
typeAlias
ZodOptionalV4: z4.$ZodOptional<T>
typeAlias
ZodStringV3: z3.ZodString
typeAlias
ZodStringV4: z4.$ZodType<string, unknown>
View source on GitHub