Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toToolsDefining Custom ToolsHuman-in-the-loop Tool ValidationMulti-Input ToolsTool Input SchemaTools as OpenAI FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsHuman-in-the-loop Tool ValidationOn this pageHuman-in-the-loop Tool ValidationThis walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler.Let's suppose we need to make use of the ShellTool. Adding this tool to an automated flow poses obvious risks. Let's see how we could enforce manual human approval of inputs going into this tool.Note: We generally recommend against using the ShellTool. There's a lot of ways to misuse it, and it's not required for most use cases. We employ it here only for demonstration purposes.from langchain.callbacks import HumanApprovalCallbackHandlerfrom langchain.tools import ShellTooltool = ShellTool()print(tool.run("echo Hello World!"))    Hello World!    Adding Human Approval‚ÄãAdding the default HumanApprovalCallbackHandler to the tool will make it so that a user has to manually approve every input to the tool before the command is actually executed.tool = ShellTool(callbacks=[HumanApprovalCallbackHandler()])print(tool.run("ls /usr"))    Do you approve of the following input? Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no.        ls /usr    yes    X11    X11R6    bin    lib    libexec    local    sbin    share    standalone    print(tool.run("ls /private"))    Do you approve of the following input? Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no.        ls /private    no
This walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler.
This walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toToolsDefining Custom ToolsHuman-in-the-loop Tool ValidationMulti-Input ToolsTool Input SchemaTools as OpenAI FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsHuman-in-the-loop Tool ValidationOn this pageHuman-in-the-loop Tool ValidationThis walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler.Let's suppose we need to make use of the ShellTool. Adding this tool to an automated flow poses obvious risks. Let's see how we could enforce manual human approval of inputs going into this tool.Note: We generally recommend against using the ShellTool. There's a lot of ways to misuse it, and it's not required for most use cases. We employ it here only for demonstration purposes.from langchain.callbacks import HumanApprovalCallbackHandlerfrom langchain.tools import ShellTooltool = ShellTool()print(tool.run("echo Hello World!"))    Hello World!    Adding Human Approval‚ÄãAdding the default HumanApprovalCallbackHandler to the tool will make it so that a user has to manually approve every input to the tool before the command is actually executed.tool = ShellTool(callbacks=[HumanApprovalCallbackHandler()])print(tool.run("ls /usr"))    Do you approve of the following input? Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no.        ls /usr    yes    X11    X11R6    bin    lib    libexec    local    sbin    share    standalone    print(tool.run("ls /private"))    Do you approve of the following input? Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no.        ls /private    no