_validate_input() — langchain Function Reference
Architecture documentation for the _validate_input() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d0875090_5168_ab1c_b4a1_6a5a1c0f0e82["_validate_input()"] dddce6a3_2420_c71d_01fe_f214c3eb2503["BasePromptTemplate"] d0875090_5168_ab1c_b4a1_6a5a1c0f0e82 -->|defined in| dddce6a3_2420_c71d_01fe_f214c3eb2503 7f533acd_fecc_61f7_633f_d2e92168a487["_format_prompt_with_error_handling()"] 7f533acd_fecc_61f7_633f_d2e92168a487 -->|calls| d0875090_5168_ab1c_b4a1_6a5a1c0f0e82 4a9a3c18_1b3a_b844_3033_a42d8d660a0c["_aformat_prompt_with_error_handling()"] 4a9a3c18_1b3a_b844_3033_a42d8d660a0c -->|calls| d0875090_5168_ab1c_b4a1_6a5a1c0f0e82 style d0875090_5168_ab1c_b4a1_6a5a1c0f0e82 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/prompts/base.py lines 159–193
def _validate_input(self, inner_input: Any) -> dict:
if not isinstance(inner_input, dict):
if len(self.input_variables) == 1:
var_name = self.input_variables[0]
inner_input_ = {var_name: inner_input}
else:
msg = (
f"Expected mapping type as input to {self.__class__.__name__}. "
f"Received {type(inner_input)}."
)
raise TypeError(
create_message(
message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT
)
)
else:
inner_input_ = inner_input
missing = set(self.input_variables).difference(inner_input_)
if missing:
msg = (
f"Input to {self.__class__.__name__} is missing variables {missing}. "
f" Expected: {self.input_variables}"
f" Received: {list(inner_input_.keys())}"
)
example_key = missing.pop()
msg += (
f"\nNote: if you intended {{{example_key}}} to be part of the string"
" and not a variable, please escape it with double curly braces like: "
f"'{{{{{example_key}}}}}'."
)
raise KeyError(
create_message(message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT)
)
return inner_input_
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does _validate_input() do?
_validate_input() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/base.py.
Where is _validate_input() defined?
_validate_input() is defined in libs/core/langchain_core/prompts/base.py at line 159.
What calls _validate_input()?
_validate_input() is called by 2 function(s): _aformat_prompt_with_error_handling, _format_prompt_with_error_handling.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free