Home / Function/ get_format_instructions() — langchain Function Reference

get_format_instructions() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fdc0557a_7650_ed36_a9a7_54a74bd977a2["get_format_instructions()"]
  978d47b2_462d_e3f1_a915_43e804fd6b61["StructuredOutputParser"]
  fdc0557a_7650_ed36_a9a7_54a74bd977a2 -->|defined in| 978d47b2_462d_e3f1_a915_43e804fd6b61
  aa3597db_802e_6a26_3f4c_43a29d1c41c7["from_response_schemas()"]
  fdc0557a_7650_ed36_a9a7_54a74bd977a2 -->|calls| aa3597db_802e_6a26_3f4c_43a29d1c41c7
  30331f05_d7c4_6919_4377_6f59c1ae79ce["_get_sub_string()"]
  fdc0557a_7650_ed36_a9a7_54a74bd977a2 -->|calls| 30331f05_d7c4_6919_4377_6f59c1ae79ce
  style fdc0557a_7650_ed36_a9a7_54a74bd977a2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/output_parsers/structured.py lines 58–107

    def get_format_instructions(
        self,
        only_json: bool = False,  # noqa: FBT001,FBT002
    ) -> str:
        """Get format instructions for the output parser.

        Example:
        ```python
        from langchain_classic.output_parsers.structured import (
            StructuredOutputParser, ResponseSchema
        )

        response_schemas = [
            ResponseSchema(
                name="foo",
                description="a list of strings",
                type="List[string]"
                ),
            ResponseSchema(
                name="bar",
                description="a string",
                type="string"
                ),
        ]

        parser = StructuredOutputParser.from_response_schemas(response_schemas)

        print(parser.get_format_instructions())  # noqa: T201

        output:
        # The output should be a Markdown code snippet formatted in the following
        # schema, including the leading and trailing "```json" and "```":
        #
        # ```json
        # {
        #     "foo": List[string]  // a list of strings
        #     "bar": string  // a string
        # }
        # ```

        Args:
            only_json: If `True`, only the json in the Markdown code snippet
                will be returned, without the introducing text.
        """
        schema_str = "\n".join(
            [_get_sub_string(schema) for schema in self.response_schemas],
        )
        if only_json:
            return STRUCTURED_FORMAT_SIMPLE_INSTRUCTIONS.format(format=schema_str)
        return STRUCTURED_FORMAT_INSTRUCTIONS.format(format=schema_str)

Domain

Frequently Asked Questions

What does get_format_instructions() do?
get_format_instructions() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/structured.py.
Where is get_format_instructions() defined?
get_format_instructions() is defined in libs/langchain/langchain_classic/output_parsers/structured.py at line 58.
What does get_format_instructions() call?
get_format_instructions() calls 2 function(s): _get_sub_string, from_response_schemas.

Analyze Your Own Codebase

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

Try Supermodel Free