Home / Function/ _get_joke_class() — langchain Function Reference

_get_joke_class() — langchain Function Reference

Architecture documentation for the _get_joke_class() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4edc076f_69be_49a9_19b6_71533096c780["_get_joke_class()"]
  c97ed773_97f8_2190_c0e8_546293fe345b["chat_models.py"]
  4edc076f_69be_49a9_19b6_71533096c780 -->|defined in| c97ed773_97f8_2190_c0e8_546293fe345b
  108c2749_d1e8_3b47_311a_c5c2ed3608b6["test_structured_output()"]
  108c2749_d1e8_3b47_311a_c5c2ed3608b6 -->|calls| 4edc076f_69be_49a9_19b6_71533096c780
  66b5b0ca_51f9_500e_a6ca_1e0d7fca1fd3["test_structured_output_async()"]
  66b5b0ca_51f9_500e_a6ca_1e0d7fca1fd3 -->|calls| 4edc076f_69be_49a9_19b6_71533096c780
  style 4edc076f_69be_49a9_19b6_71533096c780 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 46–74

def _get_joke_class(  # noqa: RET503
    schema_type: Literal["pydantic", "typeddict", "json_schema"],
) -> Any:
    class Joke(BaseModel):
        """Joke to tell user."""

        setup: str = Field(description="question to set up a joke")
        punchline: str = Field(description="answer to resolve the joke")

    def validate_joke(result: Any) -> bool:
        return isinstance(result, Joke)

    class JokeDict(TypedDict):
        """Joke to tell user."""

        setup: Annotated[str, ..., "question to set up a joke"]
        punchline: Annotated[str, ..., "answer to resolve the joke"]

    def validate_joke_dict(result: Any) -> bool:
        return all(key in {"setup", "punchline"} for key in result)

    if schema_type == "pydantic":
        return Joke, validate_joke

    if schema_type == "typeddict":
        return JokeDict, validate_joke_dict

    if schema_type == "json_schema":
        return Joke.model_json_schema(), validate_joke_dict

Domain

Subdomains

Frequently Asked Questions

What does _get_joke_class() do?
_get_joke_class() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is _get_joke_class() defined?
_get_joke_class() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 46.
What calls _get_joke_class()?
_get_joke_class() is called by 2 function(s): test_structured_output, test_structured_output_async.

Analyze Your Own Codebase

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

Try Supermodel Free