- Define a prompt.
- Create an LLM instance.
- Wrap both in a chain.
- Invoke the chain with inputs.
Quick example: a minimal Chat LLM chain
The example below demonstrates a minimal ChatOpenAI + ChatPromptTemplate + LLMChain setup. Note the updated import paths that match common LangChain usage.Typical chain output
A typical returned result (dictionary) contains the inputs and the generated text. Example:Why enable LangChain debug logging?
As chains grow in complexity—multiple components, custom transforms, callbacks, or several LLM calls—it’s easy to lose visibility into what happened during execution. LangChain provides a global debug flag that instruments runs and prints structured, per-component logs showing inputs, prompts, outputs, and timing. This visibility helps you:- Diagnose unexpected outputs or logic errors.
- Inspect intermediate prompts and transformed inputs.
- Measure token usage and per-component latency.
- Identify which component produced an error or unexpected text.
Enabling global debug logging
Turn on global debug tracing with:Sample debug output (abridged)
When debug is enabled, LangChain prints a structured trace. The example below is normalized for clarity:Interpreting the debug tags
Use the following as a quick reference to the most common log tags:Example LLM output metadata
The LLM output and the chain run often include metadata such as token usage and model identification. Example:When to enable debug logs
- During development and troubleshooting.
- When iterating on prompt engineering and wanting to inspect the exact prompt(s) sent.
- To measure token usage and latency for cost/optimization decisions.
- While building or validating multi-component chains to see intermediate inputs/outputs.
Enable
set_debug(True) while developing or troubleshooting chains to obtain a detailed execution trace of each component. Debug logs may contain sensitive data—do not enable them in production or when handling private data.