fix(core): improve langsmith loader error messages#35648
fix(core): improve langsmith loader error messages#35648Divy yadav (dvy246) wants to merge 2 commits intolangchain-ai:masterfrom
Conversation
Merging this PR will not alter performance
|
Ethan T. (gambletan)
left a comment
There was a problem hiding this comment.
Nice improvement to error reporting in the LangSmith loader. A few specific observations:
-
_get_content_from_inputsis well-structured: The progressive path tracking viatraversed_keysgives clear error messages like"missing key 'third' under 'first'". This is much more debuggable than a bareKeyErrorfromcontent[key]. -
Type check before key access: The
isinstance(content, Mapping)guard (line ~155) catches the case where traversal hits a non-dict value mid-path (e.g.,content_key="a.b"butinputs["a"]is a string). The error message clearly identifies the type mismatch. Good. -
ValueErrormessage on__init__: The new message"Received both client and client_kwargs..."is clear and actionable. Previously the bareraise ValueErrorgave no guidance at all. -
Test for the init validation:
test_init_with_client_and_client_kwargs_raisesusespytest.raises(ValueError, match=...)which validates both the exception type and the message. Clean. -
Minor: In
_get_content_from_inputs, thefull_pathvariable is computed as".".join(content_key)which could be an empty string ifcontent_keyis empty. However, whencontent_keyis empty, thefor key in content_keyloop never executes andcontent(which isinputs) is returned directly, so this is fine —full_pathis never used in the empty case. -
Suggestion: The function currently raises
KeyErrorfor missing/invalid keys. Since this is a user-facing configuration error (wrongcontent_key), you might consider raisingValueErrorinstead, which is more conventional for "bad argument" scenarios.KeyErroris typically for dict-style access patterns. That said, the original code raisedKeyErrorimplicitly, so keeping it asKeyErrormaintains backward compatibility for anyone catching it.
Overall a solid usability improvement. LGTM.
Summary
Improve
LangSmithLoadererror handling by surfacing clearer exceptions for conflicting client configuration and invalid nestedcontent_keypaths. Valid loader behavior is unchanged; this only improves invalid-input diagnostics.Testing
make formatmake lintmake test TEST_FILE=tests/unit_tests/document_loaders/test_langsmith.py