validate_prompt() — langchain Function Reference
Architecture documentation for the validate_prompt() function in agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD df20f73d_d278_027e_8a2e_0cb139b9cff4["validate_prompt()"] c55759c0_8c32_142f_44ff_2733a473d3e2["Agent"] df20f73d_d278_027e_8a2e_0cb139b9cff4 -->|defined in| c55759c0_8c32_142f_44ff_2733a473d3e2 style df20f73d_d278_027e_8a2e_0cb139b9cff4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/agent.py lines 820–847
def validate_prompt(self) -> Self:
"""Validate that prompt matches format.
Args:
values: Values to validate.
Returns:
Validated values.
Raises:
ValueError: If `agent_scratchpad` is not in prompt.input_variables
and prompt is not a FewShotPromptTemplate or a PromptTemplate.
"""
prompt = self.llm_chain.prompt
if "agent_scratchpad" not in prompt.input_variables:
logger.warning(
"`agent_scratchpad` should be a variable in prompt.input_variables."
" Did not find it, so adding it at the end.",
)
prompt.input_variables.append("agent_scratchpad")
if isinstance(prompt, PromptTemplate):
prompt.template += "\n{agent_scratchpad}"
elif isinstance(prompt, FewShotPromptTemplate):
prompt.suffix += "\n{agent_scratchpad}"
else:
msg = f"Got unexpected prompt type {type(prompt)}"
raise ValueError(msg)
return self
Domain
Subdomains
Source
Frequently Asked Questions
What does validate_prompt() do?
validate_prompt() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is validate_prompt() defined?
validate_prompt() is defined in libs/langchain/langchain_classic/agents/agent.py at line 820.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free