Skip to content

fix(langchain): remove trailing whitespace causing ruff W291 lint failure#299

Closed
lmolkova with Copilot wants to merge 27 commits into
mainfrom
copilot/fix-lint-instrumentation-genai-langchain
Closed

fix(langchain): remove trailing whitespace causing ruff W291 lint failure#299
lmolkova with Copilot wants to merge 27 commits into
mainfrom
copilot/fix-lint-instrumentation-genai-langchain

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes trailing whitespace (ruff W291) on line 244 of tests/test_llm_call.py that caused the lint / instrumentation-genai-langchain CI job to fail.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Ran ruff check instrumentation/opentelemetry-instrumentation-genai-langchain locally — all checks passed.

  • Test A

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

bhumikadangayach and others added 25 commits July 22, 2026 00:14
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
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.
Co-authored-by: Liudmila Molkova <neskazu@gmail.com>
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 22, 2026

Copy link
Copy Markdown

Pull request dashboard status

Status last refreshed: 2026-07-22 06:17:50 UTC.

  • Status: Closed.

This automated status or its linked feedback items may be incorrect. If something looks wrong, report it with the result you expected.

Copilot AI added 2 commits July 22, 2026 06:08
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
Copilot AI requested a review from lmolkova July 22, 2026 06:10
@lmolkova lmolkova closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants