How to inspect runnables
Source: langchain

# How to inspect runnables:::info PrerequisitesThis guide assumes familiarity with the following concepts:- [LangChain Expression Language (LCEL)](/docs/concepts/#langchain-expression-language)- [Chaining runnables](/docs/how_to/sequence/):::Once you create a runnable with [LangChain Expression Language](/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](/docs/how_to/debugging) instead.First, let's create an example chain. We will create one that does retrieval:```python%pip install -qU langchain langchain-openai faiss-cpu tiktoken``````pythonfrom 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())```## Get a graphYou can use the `get_graph()` method to get a graph representation of the runnable:```pythonchain.get_graph()```## Print a graphWhile that is not super legible, you can use the `print_ascii()` method to show that graph in a way that's easier to understand:```pythonchain.get_graph().print_ascii()```               +---------------------------------+                        | Parallel<context,question>Input |                        +---------------------------------+                                 **               **                                     ***                   ***                                **                         **               +----------------------+              +-------------+      | VectorStoreRetriever |              | Passthrough |      +----------------------+              +-------------+                          **               **                                          ***         ***                                               **     **                                    +----------------------------------+                       | Parallel<context,question>Output |                       +----------------------------------+                                         *                                                          *                                                          *                                               +--------------------+                                     | ChatPromptTemplate |                                     +--------------------+                                                *                                                          *                                                          *                                                   +------------+                                             | ChatOpenAI |                                             +------------+                                                    *                                                          *                                                          *                                                +-----------------+                                        | StrOutputParser |                                        +-----------------+                                                  *                                                          *                                                          *                                             +-----------------------+                                  | StrOutputParserOutput |                                  +-----------------------+              ## Get the promptsYou may want to see just the prompts that are used in a chain with the `get_prompts()` method:```pythonchain.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 stepsYou'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](/docs/how_to/debugging).```python```