← All insightsIntegration

How to use LangChain with Python for DevOps

CodeWizard Engineering · 6 April 2025 · 3 min read · Intermediate

LangChain and Python for DevOps are a common pairing in a modern DevOps stack. Here is how they fit together and a practical way to wire them up.

Where LangChain fits

LangChain is a framework for composing LLM applications: prompts, chains, tools, memory and retrieval-augmented generation (RAG), with LangSmith for tracing and evaluating agent behaviour.

python
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_community.vectorstores import FAISS

vs = FAISS.from_texts(docs, OpenAIEmbeddings())
retriever = vs.as_retriever(search_kwargs={'k': 4})
llm = ChatOpenAI(model='gpt-4o-mini', temperature=0)

def answer(q):
    ctx = '\n'.join(d.page_content for d in retriever.invoke(q))
    return llm.invoke(f'Use only this context:\n{ctx}\n\nQ: {q}').content

Where Python for DevOps fits

Python is the default scripting language for DevOps automation: readable, batteries-included, and backed by SDKs for every cloud and tool, so you can replace brittle Bash with maintainable scripts.

python
import requests
from requests.adapters import HTTPAdapter, Retry

s = requests.Session()
s.mount('https://', HTTPAdapter(max_retries=Retry(total=3, backoff_factor=0.5,
         status_forcelist=[502, 503, 504])))
r = s.get('https://api.example.com/health', timeout=5)
r.raise_for_status()
print(r.json())

Making them work together

  • Evaluate against a golden dataset in CI before shipping prompts
  • Bound retrieval (top-k) and cache embeddings
  • Use virtualenvs and pin dependencies (requirements.txt / pip-tools)
  • Add type hints and run mypy + ruff in CI

Want this pairing set up properly, with docs and handover? That is exactly the kind of work CodeWizard's embedded senior engineers do - and both LangChain and Python for DevOps have active community groups you can join for free.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult