langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://smith.langchain.com/
MIT License
387 stars 71 forks source link

[Python] Deeper Copy #735

Closed hinthornw closed 4 months ago

hinthornw commented 4 months ago

For some code paths currently, if you mutate inputs/outputs within Xs of invocation, langsmith will log the mutated value, which is confusing and the wrong behavior.

We can't naively use deepcopy, as many valid python objects cannot be copied.

This PR creates a compromise solution that attempts to deepcopy and then falls back to copying up to depth 4 while handling errors.

Will hopefully resolve #706 . Placed before the hide_* as well so that if people want to mutate the dict when filtering it doesn't impact the execution flow.