UNPKG

langchain

Version:
34 lines • 1.31 kB
import { AgentMiddleware } from "./types.js"; /** * Middleware that throws {@link ModelRefusalError} when the model refuses. * * Providers report a refusal, such as a safety-policy refusal, as a successful * response, so without this middleware the agent run ends as if it succeeded. * The middleware checks each model response for a `refusal` content block, * including refusals that fail to parse under a structured `responseFormat`. * It does not detect refusals the model writes as ordinary text. * * List it after {@link modelFallbackMiddleware} so the fallback catches the * error and retries the request on the next model. `modelRetryMiddleware` does * not retry refusals. * * @example * ```ts * import { * createAgent, * modelFallbackMiddleware, * modelRefusalMiddleware, * } from "langchain"; * * const agent = createAgent({ * model: "anthropic:claude-sonnet-5-5", * tools: [], * middleware: [ * modelFallbackMiddleware("openai:gpt-6.1-sol"), * modelRefusalMiddleware(), * ], * }); * ``` */ export declare function modelRefusalMiddleware(): AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | import("@langchain/core/tools").ClientTool)[], readonly []>; //# sourceMappingURL=modelRefusal.d.ts.map