LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentstypesInferStructuredResponse
Type●Since v1.7

InferStructuredResponse

Utility type to extract the parsed response type from a ResponseFormat strategy.

Maps ToolStrategy<T>, ProviderStrategy<T>, and TypedToolStrategy<T> to T (the parsed output type), so that structuredResponse is correctly typed as the schema's inferred type rather than the strategy wrapper.

When no responseFormat is provided (i.e. T defaults to the full SupportedResponseFormat union), this resolves to ResponseFormatUndefined so that structuredResponse is excluded from the agent's output state.

Copy
InferStructuredResponse: SupportedResponseFormat extends T  ResponseFormatUndefined : T extends TypedToolStrategy<
  U
>  U : T extends ToolStrategy<U>  U : T extends ProviderStrategy<U>  U : ResponseFormatUndefined

Example

Copy
type T1 = InferStructuredResponse<ToolStrategy<{ city: string }>>; // { city: string }
type T2 = InferStructuredResponse<ProviderStrategy<{ answer: string }>>; // { answer: string }
type T3 = InferStructuredResponse<TypedToolStrategy<{ city: string }>>; // { city: string }
type T4 = InferStructuredResponse<SupportedResponseFormat>; // ResponseFormatUndefined (default/unset)
View source on GitHub