Prompts, models, parsers, and chains all have something in common. They're runnables. Every runnable has the same methods, so you use them all the same way.
Every runnable has invoke, for one input. Batch, for a list of inputs. Stream, to get output in pieces. And async versions of each, starting with a, like a invoke. Because a whole chain is also a runnable, you can stream or batch an entire chain, just like a single model.
Here's a chain of prompt, model, and parser. Because it's a runnable, we can batch it, just like we batched a model. Run it. Three topics go in, three plain strings come out, in order. We didn't write any extra code to make the chain support batching.
runnable_batch.pypython
from langchain.chat_models import init_chat_modelfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.output_parsers import StrOutputParsermodel = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)prompt = ChatPromptTemplate.from_template("One word that rhymes with {word}. Word only.")chain = prompt | model | StrOutputParser()words = chain.batch([{"word": "book"}, {"word": "page"}, {"word": "shelf"}])print(words)
Everything you pipe together is a runnable, with invoke, batch, stream, and async versions. Chains get all of them for free. Next, turning your own functions into runnables.