Home / Function/ from_messages_and_schema() — langchain Function Reference

from_messages_and_schema() — langchain Function Reference

Architecture documentation for the from_messages_and_schema() function in structured.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  671e8ad1_3f0b_a5a0_df25_a84eee8eb0e8["from_messages_and_schema()"]
  01d2a80d_3f01_b64b_5fdb_faadceb183fd["StructuredPrompt"]
  671e8ad1_3f0b_a5a0_df25_a84eee8eb0e8 -->|defined in| 01d2a80d_3f01_b64b_5fdb_faadceb183fd
  style 671e8ad1_3f0b_a5a0_df25_a84eee8eb0e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/structured.py lines 87–136

    def from_messages_and_schema(
        cls,
        messages: Sequence[MessageLikeRepresentation],
        schema: dict | type,
        **kwargs: Any,
    ) -> ChatPromptTemplate:
        """Create a chat prompt template from a variety of message formats.

        Examples:
            Instantiation from a list of message templates:

            ```python
            from langchain_core.prompts import StructuredPrompt


            class OutputSchema(BaseModel):
                name: str
                value: int


            template = StructuredPrompt(
                [
                    ("human", "Hello, how are you?"),
                    ("ai", "I'm doing well, thanks!"),
                    ("human", "That's good to hear."),
                ],
                OutputSchema,
            )
            ```

        Args:
            messages: Sequence of message representations.

                A message can be represented using the following formats:

                1. `BaseMessagePromptTemplate`
                2. `BaseMessage`
                3. 2-tuple of `(message type, template)`; e.g.,
                    `("human", "{user_input}")`
                4. 2-tuple of `(message class, template)`
                5. A string which is shorthand for `("human", template)`; e.g.,
                    `"{user_input}"`
            schema: A dictionary representation of function call, or a Pydantic model.
            **kwargs: Any additional kwargs to pass through to
                `ChatModel.with_structured_output(schema, **kwargs)`.

        Returns:
            A structured prompt template
        """
        return cls(messages, schema, **kwargs)

Domain

Subdomains

Frequently Asked Questions

What does from_messages_and_schema() do?
from_messages_and_schema() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/structured.py.
Where is from_messages_and_schema() defined?
from_messages_and_schema() is defined in libs/core/langchain_core/prompts/structured.py at line 87.

Analyze Your Own Codebase

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

Try Supermodel Free