Skip to main content
This tutorial walks through a minimal LCEL (LangChain Core Execution Language) chain: a prompt -> ChatOpenAI LLM -> StrOutputParser. It demonstrates composing components with the | operator, invoking the chain, and inspecting input/output schemas. This is the canonical “hello world” of LCEL: simple, composable, and directly readable. Quick links:

1 — Import components and define prompt, LLM, and output parser

First, import the required pieces and create the prompt template, the ChatOpenAI LLM instance, and the StrOutputParser that converts model output to a plain Python string.

2 — Compose the LCEL chain

Use the | (pipe) operator to connect components. Outputs are automatically mapped to the next component’s inputs at runtime:
This composition means:
  • The prompt component produces data keyed by the prompt’s output schema.
  • The LLM component consumes that data (messages/metadata) and produces a chat-style output.
  • The output parser consumes the LLM output and returns a final Python value (here, a str).

3 — Invoke the chain

Call the chain’s invoke method with the prompt input fields. In this prompt, the placeholder key is question:
Example console output (model wording will vary):
StrOutputParser simply returns the LLM response as a plain Python string.

4 — Inspecting input and output schemas

Every LCEL component exposes an input_schema and output_schema. This makes composition safe and transparent: LangChain Core maps outputs to the next component’s inputs automatically, so you can focus on composing components instead of manually transforming data. To view the chain-level schemas:
Example JSON for the chain input schema:
Example JSON for the chain output schema:
To inspect the LLM’s richer schemas (inputs accept messages, metadata, and kwargs; outputs follow a chat-style structure):
Truncated example JSON for the LLM input schema:
Truncated example JSON for the LLM output schema:

5 — Component summary

6 — Key takeaway and next steps

  • Each LCEL component defines explicit input_schema and output_schema. The | operator composes components and LangChain Core maps data between them automatically.
  • This pattern removes boilerplate transformation code and encourages building small, reusable components.
Next steps:
  • Try implementing a custom LCEL component that follows the LCEL interface so it can be piped into chains just like built-ins.
  • Explore RunnablePassthrough as a foundational example of a simple, composable component.
Further reading:

Watch Video