Home / Function/ _load_examples() — langchain Function Reference

_load_examples() — langchain Function Reference

Architecture documentation for the _load_examples() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  099e19d8_ca18_6380_42d7_5dc376299f3d["_load_examples()"]
  968242b5_edb4_6604_0d16_e821da9180f5["loading.py"]
  099e19d8_ca18_6380_42d7_5dc376299f3d -->|defined in| 968242b5_edb4_6604_0d16_e821da9180f5
  a95ffdb2_1800_1638_7e16_d0060630d74c["_load_few_shot_prompt()"]
  a95ffdb2_1800_1638_7e16_d0060630d74c -->|calls| 099e19d8_ca18_6380_42d7_5dc376299f3d
  style 099e19d8_ca18_6380_42d7_5dc376299f3d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/loading.py lines 64–82

def _load_examples(config: dict) -> dict:
    """Load examples if necessary."""
    if isinstance(config["examples"], list):
        pass
    elif isinstance(config["examples"], str):
        path = Path(config["examples"])
        with path.open(encoding="utf-8") as f:
            if path.suffix == ".json":
                examples = json.load(f)
            elif path.suffix in {".yaml", ".yml"}:
                examples = yaml.safe_load(f)
            else:
                msg = "Invalid file format. Only json or yaml formats are supported."
                raise ValueError(msg)
        config["examples"] = examples
    else:
        msg = "Invalid examples format. Only list or string are supported."
        raise ValueError(msg)  # noqa:TRY004
    return config

Subdomains

Frequently Asked Questions

What does _load_examples() do?
_load_examples() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/loading.py.
Where is _load_examples() defined?
_load_examples() is defined in libs/core/langchain_core/prompts/loading.py at line 64.
What calls _load_examples()?
_load_examples() is called by 1 function(s): _load_few_shot_prompt.

Analyze Your Own Codebase

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

Try Supermodel Free