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 FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsTool Input SchemaTool Input SchemaBy default, tools infer the argument schema by inspecting the function signature. For more strict requirements, custom input schema can be specified, along with custom validation logic.from typing import Any, Dictfrom langchain.agents import AgentType, initialize_agentfrom langchain.llms import OpenAIfrom langchain.tools.requests.tool import RequestsGetTool, TextRequestsWrapperfrom pydantic import BaseModel, Field, root_validatorllm = OpenAI(temperature=0)pip install tldextract > /dev/null        [notice] A new release of pip is available: 23.0.1 -> 23.1    [notice] To update, run: pip install --upgrade pipimport tldextract_APPROVED_DOMAINS = {    "langchain",    "wikipedia",}class ToolInputSchema(BaseModel):    url: str = Field(...)    @root_validator    def validate_query(cls, values: Dict[str, Any]) -> Dict:        url = values["url"]        domain = tldextract.extract(url).domain        if domain not in _APPROVED_DOMAINS:            raise ValueError(                f"Domain {domain} is not on the approved list:"                f" {sorted(_APPROVED_DOMAINS)}"            )        return valuestool = RequestsGetTool(    args_schema=ToolInputSchema, requests_wrapper=TextRequestsWrapper())agent = initialize_agent(    [tool], llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=False)# This will succeed, since there aren't any arguments that will be triggered during validationanswer = agent.run("What's the main title on
By default, tools infer the argument schema by inspecting the function signature. For more strict requirements, custom input schema can be specified, along with custom validation logic.
By default, tools infer the argument schema by inspecting the function signature. For more strict requirements, custom input schema can be specified, along with custom validation logic. ->: 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 FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsTool Input SchemaTool Input SchemaBy default, tools infer the argument schema by inspecting the function signature. For more strict requirements, custom input schema can be specified, along with custom validation logic.from typing import Any, Dictfrom langchain.agents import AgentType, initialize_agentfrom langchain.llms import OpenAIfrom langchain.tools.requests.tool import RequestsGetTool, TextRequestsWrapperfrom pydantic import BaseModel, Field, root_validatorllm = OpenAI(temperature=0)pip install tldextract > /dev/null        [notice] A new release of pip is available: 23.0.1 -> 23.1    [notice] To update, run: pip install --upgrade pipimport tldextract_APPROVED_DOMAINS = {    "langchain",    "wikipedia",}class ToolInputSchema(BaseModel):    url: str = Field(...)    @root_validator    def validate_query(cls, values: Dict[str, Any]) -> Dict:        url = values["url"]        domain = tldextract.extract(url).domain        if domain not in _APPROVED_DOMAINS:            raise ValueError(                f"Domain {domain} is not on the approved list:"                f" {sorted(_APPROVED_DOMAINS)}"            )        return valuestool = RequestsGetTool(    args_schema=ToolInputSchema, requests_wrapper=TextRequestsWrapper())agent = initialize_agent(    [tool], llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=False)# This will succeed, since there aren't any arguments that will be triggered during validationanswer = agent.run("What's the main title on