_get_prompt() — langchain Function Reference
Architecture documentation for the _get_prompt() function in runner_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD cb0a59f9_bf61_2368_e170_04f16da99179["_get_prompt()"] 8253c602_7d0c_9195_a7e1_3e9b19304131["runner_utils.py"] cb0a59f9_bf61_2368_e170_04f16da99179 -->|defined in| 8253c602_7d0c_9195_a7e1_3e9b19304131 6e6ec2d6_6138_30d5_cc46_459846fde288["_validate_example_inputs_for_language_model()"] 6e6ec2d6_6138_30d5_cc46_459846fde288 -->|calls| cb0a59f9_bf61_2368_e170_04f16da99179 5dad9d8a_ecf9_b785_9a01_d927f6bea73e["_arun_llm()"] 5dad9d8a_ecf9_b785_9a01_d927f6bea73e -->|calls| cb0a59f9_bf61_2368_e170_04f16da99179 916eedb8_7d10_72b9_9829_105f8ada65ab["_run_llm()"] 916eedb8_7d10_72b9_9829_105f8ada65ab -->|calls| cb0a59f9_bf61_2368_e170_04f16da99179 style cb0a59f9_bf61_2368_e170_04f16da99179 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/smith/evaluation/runner_utils.py lines 247–294
def _get_prompt(inputs: dict[str, Any]) -> str:
"""Get prompt from inputs.
Args:
inputs: The input dictionary.
Returns:
A string prompt.
Raises:
InputFormatError: If the input format is invalid.
"""
if not inputs:
msg = "Inputs should not be empty."
raise InputFormatError(msg)
prompts = []
if "prompt" in inputs:
if not isinstance(inputs["prompt"], str):
msg = f"Expected string for 'prompt', got {type(inputs['prompt']).__name__}"
raise InputFormatError(msg)
prompts = [inputs["prompt"]]
elif "prompts" in inputs:
if not isinstance(inputs["prompts"], list) or not all(
isinstance(i, str) for i in inputs["prompts"]
):
msg = (
"Expected list of strings for 'prompts',"
f" got {type(inputs['prompts']).__name__}"
)
raise InputFormatError(msg)
prompts = inputs["prompts"]
elif len(inputs) == 1:
prompt_ = next(iter(inputs.values()))
if isinstance(prompt_, str):
prompts = [prompt_]
elif isinstance(prompt_, list) and all(isinstance(i, str) for i in prompt_):
prompts = prompt_
else:
msg = f"LLM Run expects string prompt input. Got {inputs}"
raise InputFormatError(msg)
else:
msg = f"LLM Run expects 'prompt' or 'prompts' in inputs. Got {inputs}"
raise InputFormatError(msg)
if len(prompts) == 1:
return prompts[0]
msg = f"LLM Run expects single prompt input. Got {len(prompts)} prompts."
raise InputFormatError(msg)
Domain
Subdomains
Source
Frequently Asked Questions
What does _get_prompt() do?
_get_prompt() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py.
Where is _get_prompt() defined?
_get_prompt() is defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py at line 247.
What calls _get_prompt()?
_get_prompt() is called by 3 function(s): _arun_llm, _run_llm, _validate_example_inputs_for_language_model.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free