Prev Next

AI / LangGraph LangChain Interview questions II

How do you monitor LangChain applications?

Monitoring LangChain applications in production means tracking latency, error rates, token usage, and response quality over time. LangSmith is the primary tool, but you can also integrate with standard observability infrastructure.

LangSmith tracing — enabled with two env vars, it captures every run automatically with full context:

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=ls__...
export LANGCHAIN_PROJECT=production-chat-v2

In LangSmith you get: latency distribution per chain step, error rate trends, token cost per request, feedback scores from users or evaluators, and the ability to filter/search runs by any metadata tag you add.

Custom metadata tagging — tag runs with user ID, feature flag, model version, etc. to enable filtering in LangSmith dashboards:

chain.invoke(
    {"input": user_query},
    config={
        "metadata": {"user_id": user_id, "ab_group": "control"},
        "tags": ["production", "rag-v2"],
    }
)

Custom callbacks for metrics — implement a callback handler that pushes latency, token counts, and error flags to your existing metrics backend (Prometheus, Datadog, CloudWatch) on each LLM call end:

class MetricsCallback(BaseCallbackHandler):
    def on_llm_end(self, response, **kwargs):
        tokens = response.llm_output.get("token_usage", {})
        prometheus_counter.inc(tokens.get("total_tokens", 0))

What two environment variables are required to enable LangSmith tracing?
What is the purpose of adding metadata tags to a chain invocation config in production?

More Related questions...

Show more question and Answers...


Comments & Discussions