langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Issue: How to conveniently disable langsmith calls?

Open kebijuelun opened this issue 2 years ago • 11 comments

Issue you'd like to raise.

When I use an existing library that includes langsmith (such as https://github.com/langchain-ai/weblangchain), but I don't have access to langsmith API as I'm still on the waitlist. How can I quickly disable the langsmith functionality without commenting out the code?

Suggestion:

No response

kebijuelun avatar Dec 03 '23 02:12 kebijuelun

🤖

Hello @kebijuelun!

I'm Dosu, a bot specially designed to assist you with your questions, bugs, or if you're looking to contribute to the project. I'm here to help you while we're waiting for a human maintainer to join the conversation.

To disable the LangSmith functionality in LangChain, you can simply avoid calling the run_on_dataset function from the langchain.smith module. This function is responsible for running the evaluation on a dataset using LangSmith. If you don't call this function, LangSmith will not be used.

Here's an example of how you might modify your code to disable LangSmith:

from langsmith import Client
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain

# Chains may have memory. Passing in a constructor function lets the
# evaluation framework avoid cross-contamination between runs.
def construct_chain():
    llm = ChatOpenAI(temperature=0)
    chain = LLMChain.from_string(
        llm,
        "What's the answer to {your_input_key}"
    )
    return chain

# Instead of calling run_on_dataset, you can directly use your chain
chain = construct_chain()
# Use your chain here

In this modified code, we're still constructing the chain, but we're not calling run_on_dataset to evaluate it with LangSmith. This effectively disables the LangSmith functionality.

As for a global configuration option or method to disable LangSmith calls, I wasn't able to find one in the LangChain repository. It's possible that such an option exists but is not documented, or it may be that no such option exists at this time. If you need further assistance, please provide more details about your use case and I'll do my best to help.

You can find more information about the run_on_dataset function and the langchain.smith module in the LangChain repository.

I hope this helps! If you have any other questions, feel free to ask.

-Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Dec 03 '23 02:12 dosubot[bot]

@kebijuelun - if you set LANGCHAIN_TRACING_V2=false (or just don't set it to true) then the tracing isn't activated

hinthornw avatar Jan 12 '24 00:01 hinthornw

How about disabling it for certain calls? we'd like to be able to track some while skip the minor simple requests

SOSADonV avatar Mar 25 '24 13:03 SOSADonV

Unsetting LANGCHAIN_TRACING_V2 doesn't disable tracing as it should. I can confirm that the environment variable is read as False in the executing Python process.

modgeosys avatar May 11 '24 23:05 modgeosys

I also see that the langsmith is sending some requests even with that env var set to false (js client)

hnykda avatar May 23 '24 11:05 hnykda

I have the same issue: I want to disable Langsmith for a specific boring runnable to saving traces.

edwardzjl avatar Jul 12 '24 09:07 edwardzjl

Same problem, really annoying

Mr-zhouyi avatar Jul 19 '24 08:07 Mr-zhouyi

I also would like to disable sending traces to langsmith for our test environment

JonathanBrenner avatar Jul 24 '24 21:07 JonathanBrenner

I also need this feature to disable it for some calls. We pre-generate a lot and there tracing is not necessary, and we are talking about thousand of traces, so it's expensive too.

NicolasHoferer avatar Jul 26 '24 13:07 NicolasHoferer

How about disabling it for certain calls? we'd like to be able to track some while skip the minor simple requests

@SOSADonV You can use this. https://api.python.langchain.com/en/latest/tracers/langchain_core.tracers.langchain.LangChainTracer.html#langchain_core.tracers.langchain.LangChainTracer

DaiIshida4869 avatar Sep 20 '24 15:09 DaiIshida4869

For anyone interested, here's a clean solution:

from langsmith import tracing_context

llm = ChatOpenAI()
with tracing_context(enabled=False):
    # Anything in this code block will **not** be traced to LangSmith
    llm.invoke("hello world")

adapted from these docs: https://docs.smith.langchain.com/observability/how_to_guides/tracing/trace_without_env_vars

VMinB12 avatar Dec 18 '24 09:12 VMinB12

Are there any plans to fix the bug where disabling langsmith by environment variable does not work? Embedding tracing_context into code for disabling is not neat.

soichisumi avatar Feb 04 '25 05:02 soichisumi

Are there any plans to fix the bug where disabling langsmith by environment variable does not work? Embedding tracing_context into code for disabling is not neat.

For the record @soichisumi I thought i was facing this with typescript too - it seems if I manually enable tracing in code, well, it'll ignore the following:

LANGCHAIN_TRACING_V2=false
LANGCHAIN_CALLBACKS_BACKGROUND=false

So in my tests at least where i was facing the issue, i just don't init telemetry unless i'm specifically testing it, and then sure enough it's not done.

May or may not be related but thought i'd mention!

mobob avatar Mar 26 '25 01:03 mobob

Hi, @kebijuelun. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You were looking for a way to disable Langsmith functionality without commenting out code.
  • @hinthornw suggested using LANGCHAIN_TRACING_V2=false, but it didn't work as expected for some users.
  • @VMinB12 provided a solution using tracing_context(enabled=False), which received positive feedback.
  • There is ongoing discussion about fixing the environment variable issue for a cleaner solution.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the LangChain repository by commenting here.
  • If there is no further activity, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Jun 25 '25 16:06 dosubot[bot]