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
  • 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 MemoryTools
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/coreutilstypes
Module●Since v0.3

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, standard schema, 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 ZodV4ArrayLike
function
isZodLiteralV3→ obj is ZodV3Like<any, any>
function
isZodLiteralV4→ obj is ZodV4Like<any, any>
function
isZodNullableV4→ obj is ZodV4NullableLike
function
isZodObjectV3→ obj is ZodV3ObjectLike
function
isZodObjectV4→ obj is ZodV4ObjectLike
function
isZodOptionalV4→ obj is ZodV4OptionalLike
function
isZodSchema→ schema is ZodV3Like<RunOutput, RunOutput>

Backward compatible isZodSchema for Zod 3

function
isZodSchemaV3→ schema is ZodV3Like<unknown, unknown>
function
isZodSchemaV4→ schema is ZodV4Like<unknown, unknown>

Interfaces

interface
InteropZodError
interface
InteropZodIssue
interface
ZodV3EffectsLike
interface
ZodV3Like
interface
ZodV3ObjectLike
interface
ZodV3TypeDef
interface
ZodV4ArrayLike
interface
ZodV4Internals
interface
ZodV4Like
interface
ZodV4NullableLike
interface
ZodV4ObjectLike
interface
ZodV4OptionalLike
interface
ZodV4PipeLike

Type Aliases

typeAlias
ChainValues: Record<string, any>
typeAlias
InferInteropZodInput: T extends ZodV3Like<unknown, Input> ? Input : T extends ZodV4Like<unknown, Input> ? Input : T extends __type ? Input : never
typeAlias
InferInteropZodOutput: T extends ZodV3Like<Output, unknown> ? Output : T extends ZodV4Like<Output, unknown> ? Output : T extends __type ? Output : never
typeAlias
InputValues: Record<K, any>
typeAlias
InteropZodDefault: T extends ZodV3Like ? ZodDefaultV3<T> : T extends ZodV4Like ? ZodDefaultV4<T> : never
typeAlias
InteropZodLiteral: ZodV3Like | ZodV4Like
typeAlias
InteropZodObject: ZodV3ObjectLike | ZodV4ObjectLike
typeAlias
InteropZodObjectShape: T extends ZodV3ObjectLike ? { [K in keyof T["shape"]]: T["shape"][K] } : T extends ZodV4ObjectLike ? { [K in keyof T["_zod"]["def"]["shape"]]: T["_zod"]["def"]["shape"][K] } : never
typeAlias
InteropZodOptional: T extends ZodV3Like ? ZodOptionalV3<T> : T extends ZodV4Like ? ZodOptionalV4<T> : never
typeAlias
InteropZodType: ZodV3Like<Output, Input> | ZodV4Like<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: ZodV3Like<T extends ZodV3Like<O, any> ? O : any>
typeAlias
ZodDefaultV4: ZodV4Like<T extends ZodV4Like<O, any> ? O : any>
typeAlias
ZodNullableV4: ZodV4Like<T extends ZodV4Like<O, any> ? O | null : any>
typeAlias
ZodObjectMain: ZodV4ObjectLike
typeAlias
ZodObjectV3: ZodV3ObjectLike
typeAlias
ZodObjectV4: ZodV4ObjectLike
typeAlias
ZodObjectV4Classic: ZodV4ObjectLike
typeAlias
ZodOptionalV3: ZodV3Like<T extends ZodV3Like<O, any> ? O | undefined : any>
typeAlias
ZodOptionalV4: ZodV4Like<T extends ZodV4Like<O, any> ? O | undefined : any>
typeAlias
ZodStringV3: ZodV3Like<string>
typeAlias
ZodStringV4: ZodV4Like<string, unknown>
View source on GitHub