Home / Function/ _create_openai_json_runnable() — langchain Function Reference

_create_openai_json_runnable() — langchain Function Reference

Architecture documentation for the _create_openai_json_runnable() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c9fa65ca_917c_8e4a_2662_8155e1c9ba25["_create_openai_json_runnable()"]
  22e1446e_2db6_2965_eef8_bf9239c6dbfc["base.py"]
  c9fa65ca_917c_8e4a_2662_8155e1c9ba25 -->|defined in| 22e1446e_2db6_2965_eef8_bf9239c6dbfc
  f3f63b38_7673_1a74_f67c_06b8e8cfcdf3["create_structured_output_runnable()"]
  f3f63b38_7673_1a74_f67c_06b8e8cfcdf3 -->|calls| c9fa65ca_917c_8e4a_2662_8155e1c9ba25
  style c9fa65ca_917c_8e4a_2662_8155e1c9ba25 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/structured_output/base.py lines 524–546

def _create_openai_json_runnable(
    output_schema: dict[str, Any] | type[BaseModel],
    llm: Runnable,
    prompt: BasePromptTemplate | None = None,
    *,
    output_parser: BaseOutputParser | BaseGenerationOutputParser | None = None,
) -> Runnable:
    if isinstance(output_schema, type) and is_basemodel_subclass(output_schema):
        output_parser = output_parser or PydanticOutputParser(
            pydantic_object=output_schema,
        )
        schema_as_dict = convert_to_openai_function(output_schema)["parameters"]
    else:
        output_parser = output_parser or JsonOutputParser()
        schema_as_dict = output_schema

    llm = llm.bind(response_format={"type": "json_object"})
    if prompt:
        if "output_schema" in prompt.input_variables:
            prompt = prompt.partial(output_schema=json.dumps(schema_as_dict, indent=2))

        return prompt | llm | output_parser
    return llm | output_parser

Subdomains

Frequently Asked Questions

What does _create_openai_json_runnable() do?
_create_openai_json_runnable() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/structured_output/base.py.
Where is _create_openai_json_runnable() defined?
_create_openai_json_runnable() is defined in libs/langchain/langchain_classic/chains/structured_output/base.py at line 524.
What calls _create_openai_json_runnable()?
_create_openai_json_runnable() is called by 1 function(s): create_structured_output_runnable.

Analyze Your Own Codebase

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

Try Supermodel Free