Home / Function/ _validate_example_inputs_for_language_model() — langchain Function Reference

_validate_example_inputs_for_language_model() — langchain Function Reference

Architecture documentation for the _validate_example_inputs_for_language_model() function in runner_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6e6ec2d6_6138_30d5_cc46_459846fde288["_validate_example_inputs_for_language_model()"]
  8253c602_7d0c_9195_a7e1_3e9b19304131["runner_utils.py"]
  6e6ec2d6_6138_30d5_cc46_459846fde288 -->|defined in| 8253c602_7d0c_9195_a7e1_3e9b19304131
  42662eb3_17b6_0aaa_f09d_12aabcf769e7["_validate_example_inputs()"]
  42662eb3_17b6_0aaa_f09d_12aabcf769e7 -->|calls| 6e6ec2d6_6138_30d5_cc46_459846fde288
  cb0a59f9_bf61_2368_e170_04f16da99179["_get_prompt()"]
  6e6ec2d6_6138_30d5_cc46_459846fde288 -->|calls| cb0a59f9_bf61_2368_e170_04f16da99179
  c56a3c0a_b0e2_287c_e948_c9d9eb18b351["_get_messages()"]
  6e6ec2d6_6138_30d5_cc46_459846fde288 -->|calls| c56a3c0a_b0e2_287c_e948_c9d9eb18b351
  style 6e6ec2d6_6138_30d5_cc46_459846fde288 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/smith/evaluation/runner_utils.py lines 346–378

def _validate_example_inputs_for_language_model(
    first_example: Example,
    input_mapper: Callable[[dict], Any] | None,
) -> None:
    if input_mapper:
        prompt_input = input_mapper(first_example.inputs or {})
        if not isinstance(prompt_input, str) and not (
            isinstance(prompt_input, list)
            and all(isinstance(msg, BaseMessage) for msg in prompt_input)
        ):
            msg = (
                "When using an input_mapper to prepare dataset example inputs"
                " for an LLM or chat model, the output must a single string or"
                " a list of chat messages."
                f"\nGot: {prompt_input} of type {type(prompt_input)}."
            )
            raise InputFormatError(msg)
    else:
        try:
            _get_prompt(first_example.inputs or {})
        except InputFormatError:
            try:
                _get_messages(first_example.inputs or {})
            except InputFormatError as err2:
                msg = (
                    "Example inputs do not match language model input format. "
                    "Expected a dictionary with messages or a single prompt."
                    f" Got: {first_example.inputs}"
                    " Please update your dataset OR provide an input_mapper"
                    " to convert the example.inputs to a compatible format"
                    " for the llm or chat model you wish to evaluate."
                )
                raise InputFormatError(msg) from err2

Domain

Subdomains

Frequently Asked Questions

What does _validate_example_inputs_for_language_model() do?
_validate_example_inputs_for_language_model() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py.
Where is _validate_example_inputs_for_language_model() defined?
_validate_example_inputs_for_language_model() is defined in libs/langchain/langchain_classic/smith/evaluation/runner_utils.py at line 346.
What does _validate_example_inputs_for_language_model() call?
_validate_example_inputs_for_language_model() calls 2 function(s): _get_messages, _get_prompt.
What calls _validate_example_inputs_for_language_model()?
_validate_example_inputs_for_language_model() is called by 1 function(s): _validate_example_inputs.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free