Closed
fix(langchain): remove trailing whitespace causing ruff W291 lint failure#299
Conversation
Adds ChatAnthropic to the list of supported chat models in the LangChain callback handler. Previously only ChatOpenAI and ChatBedrock were instrumented; Anthropic users received no spans. Changes: - Add ChatAnthropic to the allowlist in on_chat_model_start - Add 'model' param key for model name extraction (Anthropic uses 'model', not 'model_name' or 'model_id') - Add 'stop_sequences' fallback for stop param (Anthropic's param name) - Add 'max_tokens' fallback for max tokens param - Add langchain-anthropic to test requirements - Add ChatAnthropic fixture and VCR cassette test Fixes #139
…with tool_use convention
Adds a VCR-backed test exercising the else branch in the stop/stop_sequences
fallback (params.get('stop') is None, params.get('stop_sequences') set),
which was previously untested. Cassette is AI-synthesized pending re-record
against the live API.
Assisted-by: Claude Sonnet 5
…ENTS.md The test_chat_anthropic_claude_sonnet_tool_call.yaml cassette was missing the required disclosure header for synthetic cassettes.
The langchain-conformance tox env was missing langchain-anthropic, causing a ModuleNotFoundError once conftest.py imports ChatAnthropic unconditionally (surfaced after rebasing onto upstream/main).
Upstream's rebase added body to the VCR match_on config, and the existing tool_call cassette was a hand-approximated recording that no longer matched the actual payload langchain-anthropic produces (max_tokens, temperature, and tool schema field order had drifted). Rebuilt the cassette body from the real payload captured via ChatAnthropic._get_request_payload() using the exact fixture params. Also removes a redundant inline import in the stop_sequences test flagged by ruff's PLC0415 (import already exists at module level).
The oldest tox env was missing langchain-anthropic entirely, causing the same ModuleNotFoundError seen earlier in the conformance env. Pinned to 0.3.0, matching the era of the other oldest-supported provider pins (langchain-openai==0.2.0, langchain-google-genai==2.0.0) and requiring langchain-core>=0.3.0, compatible with this package's own langchain>=0.3.21 floor.
…stop_sequences
Per eternalcuriouslearner's suggestion: when stop_sequences is passed
at ChatAnthropic construction time rather than via bind() or invoke(),
it only appears in serialized['kwargs'], never in invocation_params.
Confirmed via debug prints (removed before commit) that the current
two-level fallback (params.get('stop') / params.get('stop_sequences'))
silently misses this case. Added a third fallback checking
serialized.get('kwargs', {}).get('stop_sequences'), with a new VCR
test covering the constructor-time path specifically.
…ty, fix typecheck Explicitly pins max_tokens=1024 in the constructor-fallback test so the request body is identical across langchain-anthropic versions (the library's own default changed between the oldest-pinned 0.3.0 and latest, causing a VCR body-match failure on the oldest env). Also fixes a pyright reportUnknownVariableType/reportUnknownMemberType error by giving serialized_kwargs an explicit dict[str, Any] annotation.
…util-genai with main
Co-authored-by: Liudmila Molkova <neskazu@gmail.com>
Pull request dashboard statusStatus last refreshed: 2026-07-22 06:17:50 UTC.
This automated status or its linked feedback items may be incorrect. If something looks wrong, report it with the result you expected. |
…strumentation-genai-langchain
Fixes lint failure: W291 trailing whitespace on line 244 of tests/test_llm_call.py in the langchain instrumentation package. Assisted-by: Claude Sonnet 4.5
Copilot
AI
changed the title
[WIP] Fix failing GitHub Actions job lint / instrumentation-genai-langchain
fix(langchain): remove trailing whitespace causing ruff W291 lint failure
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes trailing whitespace (ruff W291) on line 244 of
tests/test_llm_call.pythat caused thelint / instrumentation-genai-langchainCI job to fail.Type of change
How has this been tested?
Ran
ruff check instrumentation/opentelemetry-instrumentation-genai-langchainlocally — all checks passed.Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.