*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to inspect runnables

On this page

How to inspect runnables
========================

Prerequisites

This guide assumes familiarity with the following concepts:

*   [LangChain Expression Language (LCEL)](/v0.2/docs/concepts/#langchain-expression-language)
*   [Chaining runnables](/v0.2/docs/how_to/sequence/)

Once you create a runnable with [LangChain Expression Language](/v0.2/docs/concepts/#langchain-expression-language), you may often want to inspect it to get a better sense for what is going on. This notebook covers some methods for doing so.

This guide shows some ways you can programmatically introspect the internal steps of chains. If you are instead interested in debugging issues in your chain, see [this section](/v0.2/docs/how_to/debugging/) instead.

First, let's create an example chain. We will create one that does retrieval:

    %pip install -qU langchain langchain-openai faiss-cpu tiktoken

    from langchain_community.vectorstores import FAISSfrom langchain_core.output_parsers import StrOutputParserfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.runnables import RunnablePassthroughfrom langchain_openai import ChatOpenAI, OpenAIEmbeddingsvectorstore = FAISS.from_texts(    ["harrison worked at kensho"], embedding=OpenAIEmbeddings())retriever = vectorstore.as_retriever()template = """Answer the question based only on the following context:{context}Question: {question}"""prompt = ChatPromptTemplate.from_template(template)model = ChatOpenAI()chain = (    {"context": retriever, "question": RunnablePassthrough()}    | prompt    | model    | StrOutputParser())

**API Reference:**[FAISS](https://api.python.langchain.com/en/latest/vectorstores/langchain_community.vectorstores.faiss.FAISS.html) | [StrOutputParser](https://api.python.langchain.com/en/latest/output_parsers/langchain_core.output_parsers.string.StrOutputParser.html) | [ChatPromptTemplate](https://api.python.langchain.com/en/latest/prompts/langchain_core.prompts.chat.ChatPromptTemplate.html) | [RunnablePassthrough](https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.passthrough.RunnablePassthrough.html) | [ChatOpenAI](https://api.python.langchain.com/en/latest/chat_models/langchain_openai.chat_models.base.ChatOpenAI.html) | [OpenAIEmbeddings](https://api.python.langchain.com/en/latest/embeddings/langchain_openai.embeddings.base.OpenAIEmbeddings.html)

Get a graph[​](#get-a-graph "Direct link to Get a graph")
---------------------------------------------------------

You can use the `get_graph()` method to get a graph representation of the runnable:

    chain.get_graph()

Print a graph[​](#print-a-graph "Direct link to Print a graph")
---------------------------------------------------------------

While that is not super legible, you can use the `print_ascii()` method to show that graph in a way that's easier to understand:

    chain.get_graph().print_ascii()

               +---------------------------------+                    | Parallel<context,question>Input |                    +---------------------------------+                             **               **                                 ***                   ***                            **                         **           +----------------------+              +-------------+  | VectorStoreRetriever |              | Passthrough |  +----------------------+              +-------------+                      **               **                                      ***         ***                                           **     **                                +----------------------------------+                   | Parallel<context,question>Output |                   +----------------------------------+                                     *                                                      *                                                      *                                           +--------------------+                                 | ChatPromptTemplate |                                 +--------------------+                                            *                                                      *                                                      *                                               +------------+                                         | ChatOpenAI |                                         +------------+                                                *                                                      *                                                      *                                            +-----------------+                                    | StrOutputParser |                                    +-----------------+                                              *                                                      *                                                      *                                         +-----------------------+                              | StrOutputParserOutput |                              +-----------------------+

Get the prompts[​](#get-the-prompts "Direct link to Get the prompts")
---------------------------------------------------------------------

You may want to see just the prompts that are used in a chain with the `get_prompts()` method:

    chain.get_prompts()

    [ChatPromptTemplate(input_variables=['context', 'question'], messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question'], template='Answer the question based only on the following context:\n{context}\n\nQuestion: {question}\n'))])]

Next steps[​](#next-steps "Direct link to Next steps")
------------------------------------------------------

You've now learned how to introspect your composed LCEL chains.

Next, check out the other how-to guides on runnables in this section, or the related how-to guide on [debugging your chains](/v0.2/docs/how_to/debugging/).

[Edit this page](https://github.com/langchain-ai/langchain/edit/master/docs/docs/how_to/inspect.ipynb)

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchain/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to use the LangChain indexing API

](/v0.2/docs/how_to/indexing/)[

Next

LangChain Expression Language Cheatsheet

](/v0.2/docs/how_to/lcel_cheatsheet/)

*   [Get a graph](#get-a-graph)
*   [Print a graph](#print-a-graph)
*   [Get the prompts](#get-the-prompts)
*   [Next steps](#next-steps)