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
JavaScriptlangchainindexproviderStrategy
Functionā—Since v1.1

providerStrategy

Creates a provider strategy for structured output using native JSON schema support.

This function is used to configure structured output for agents when the underlying model supports native JSON schema output (e.g., OpenAI's gpt-4o, gpt-4o-mini, and newer models). Unlike toolStrategy, which uses function calling to extract structured output, providerStrategy leverages the provider's native structured output capabilities, resulting in more efficient and reliable schema enforcement.

When used with a model that supports JSON schema output, the model will return responses that directly conform to the provided schema without requiring tool calls. This is the recommended approach for structured output when your model supports it.

Copy
providerStrategy<
  T extends InteropZodType<unknown>
>(responseFormat: T | __type): ProviderStrategy<T extends InteropZodType<U>  U : never>

Used in Docs

  • Structured output

Parameters

NameTypeDescription
responseFormat*T | __type

The schema to enforce, either a Zod schema, a JSON schema object, or an options object with schema and optional strict flag

Example 1

Copy
import { providerStrategy, createAgent } from "langchain";
import { z } from "zod";

const agent = createAgent({
  model: "claude-haiku-4-5",
  responseFormat: providerStrategy(
    z.object({
      answer: z.string().describe("The answer to the question"),
      confidence: z.number().min(0).max(1),
    })
  ),
});

Example 2

Copy
// Using strict mode for stricter schema enforcement
const agent = createAgent({
  model: "claude-haiku-4-5",
  responseFormat: providerStrategy({
    schema: z.object({
      name: z.string(),
      age: z.number(),
    }),
    strict: true
  }),
});
View source on GitHub