Public report of langchain-ai/langchain, published 14 November 2026. It has the same score, grades and number of
findings as the full report. The details of security findings (where they are in the code, which known
vulnerabilities and which passwords or keys were found) are left out, so nobody can use them against the project.
Public
Executive reportMeasured under the Code Assurance Index, an open standard for code quality, using its published scoring rules (rubric version 2026.11.4). Assert signed this survey and filed it in the standard's public register, where anyone can look it up by its survey ID. Check this survey →
Signed and filed in the standard's public register, 14 November 2026, 00:57 UTC · Survey ID cd_27d4764dd9804e5193316d40e21079bd
langchain-ai/langchain
Measured 14 November 2026, 00:55 UTC, at code version ea17e48
Test reliability is not measured: The suite could not be re-run, but the repository declares tests of its own unreliable.
CAI scoreAt riskDown 2 since the last survey
The score is built from these lenses. Each lens grades one area of the code, such as how easy it is to change or how well it is protected. The weakest lens counts most, so one weak area pulls the score down instead of being averaged away.
A large codebase: 184,648 lines of product code in 22 projects, tests not counted · Estimated rebuild effort: about 2.6 person-years · Weakest lens: Production Readiness, 53
Findings by how serious they are
49 critical1300 serious120 minor
15 dimensions are left out of the score. For each one, we either couldn't measure it in this code, or found no evidence of the safeguard we look for, such as a tested backup restore. They count neither for nor against the score, and Limitations lists each one with its reason.
This survey was produced by
Canine Code Analyzer
Producer
Canine Development
Analyzer
Canine Code Analyzer engine 1.0.0
Measured
14 November 2026, 00:55 UTC
A measurement, not a certificate. The Code Assurance Index records a number
together with the evidence it was worked out from, so anyone can recalculate it, but it doesn't certify or guarantee
the code. The standard was written by Canine Development, which also builds the Canine Code Analyzer. It is open to any tool that
implements it, and today the Canine Code Analyzer is the only one that does.
A critical security finding is open, such as a library with a known critical vulnerability or a password or key found in the code. The score itself is unchanged, but its band shows At risk until the finding is fixed. See the Security and Compliance lens.
The score is deterministic, which means the same code always gets the same score. We work it out with tools that follow published rules, and an AI model never decides it, so anyone who applies the same rules to the same code gets the same number. How it is done is explained under Methodology ▸
52of 52 dimensions measured by tools.
1458of 1469 findings point to an exact file and line, so you can open each one in the code. The other 11 concern the repository as a whole, such as missing documentation.
52dimensions across 6 lenses, read from 184,648 lines of product code in 22 projects.
langchain-ai/langchain is rated At risk because critical security findings are open. It scores 62 out of 100, which the At risk rating leaves unchanged. We judged it as a preview release, against a lower bar.
Production Readiness, at 53, is the weakest lens and counts most in the score. The best first step for the work it takes is replacing the seven passwords or keys found in the code's history, worth about 2 points. Adding automated security scanning would lift Production Readiness itself, worth about 4 points. Raising Production Readiness to 62 would lift the score to about 66.
Twenty-two weaknesses in the code could be used by an attacker. Seven passwords or keys are open to anyone who can read the repository, and five secrets can leak from the build pipeline. Fixing the weaknesses the scanner points to, replacing each exposed password or key and limiting each secret to its own step would close these risks. Updating the vulnerable packages would fix the four packages with a known security hole, and the three pipeline steps that install packages without pinning their versions need the packages they install pinned to exact versions. The four tests the project itself marks as unreliable need fixing or deleting.
The product code is 184,648 lines, about €380,000 to rebuild.
A lens is capped at Adequate while one of its dimensions scores below 4 out of 10, however well the rest of the lens does. That way a serious problem in one place always shows in the lens's rating.
How the score is built: what each lens counts forThe lenses don't count equally. The weakest lens counts most, the next weakest a little less, and so on, so a weak area pulls the score down instead of being averaged away. In the bar below, each part's width shows how much that lens counts and its colour shows its rating. Improving the widest part moves the score most, and as that lens improves, it counts for less, because another lens becomes the weakest.
If Production Readiness rose from 53 to 62, the lowest score rated Strong, the score would rise from 62 to about 66.
Code composition: what the lines of code are
Product code 54%Tests 46%
New since the last survey: 345 findings
These 345 critical or serious findings weren't in the previous survey, on 25 October 2026. The first 100 are listed here, and the findings file in the download package lists them all.
Code Duplication · Edited copy of a member (29 corresponding lines) libs/core/langchain_core/language_models/chat_models.py
Code Duplication · Members sharing a duplicated core (9 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py
Code Duplication · Members sharing a duplicated core (6 members, 50+ identical tokens) libs/core/langchain_core/messages/content.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/runnables/base.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain_v1/langchain/agents/middleware/types.py
Code Duplication · Edited copy of a member (108 corresponding lines) libs/partners/perplexity/langchain_perplexity/chat_models.py
Code Duplication · Edited copy of a member (129 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py
Code Duplication · Edited copy of a member (71 corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py
Code Duplication · Edited copy of a member (86 corresponding lines) libs/langchain_v1/langchain/agents/factory.py
Code Duplication · Edited copy of a member (59 corresponding lines) libs/partners/perplexity/langchain_perplexity/chat_models.py
Code Duplication · Edited copy of a member (63 corresponding lines) REDACTED
Code Duplication · Edited copy of a member (79 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py
Code Duplication · Edited copy of a member (67 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py
Code Duplication · Edited copy of a member (51 corresponding lines) REDACTED
Code Duplication · Edited copy of a member (64 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py
Code Duplication · Edited copy of a member (85 corresponding lines) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py
Code Duplication · Edited copy of a member (71 corresponding lines) libs/core/langchain_core/language_models/_compat_bridge.py
Code Duplication · Edited copy of a member (73 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py
Code Duplication · Edited copy of a member (60 corresponding lines) libs/core/langchain_core/language_models/llms.py
Code Duplication · Edited copy of a member (70 corresponding lines) libs/langchain/langchain_classic/agents/agent.py
Code Duplication · Edited copy of a member (67 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (61 corresponding lines) libs/partners/openai/langchain_openai/embeddings/base.py
Code Duplication · Edited copy of a member (54 corresponding lines) libs/core/langchain_core/runnables/retry.py
Code Duplication · Edited copy of a member (61 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py
Code Duplication · Edited copy of a member (48 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py
Code Duplication · Edited copy of a member (81 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (74 corresponding lines) libs/langchain/langchain_classic/indexes/_sql_record_manager.py
Code Duplication · Edited copy of a member (90 corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py
Code Duplication · Edited copy of a member (62 corresponding lines) libs/langchain/langchain_classic/agents/agent_iterator.py
Code Duplication · Edited copy of a member (44 corresponding lines) libs/core/langchain_core/_security/_transport.py
Code Duplication · Edited copy of a member (49 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (36 corresponding lines) libs/core/langchain_core/language_models/llms.py
Code Duplication · Edited copies of one member (4 members, 50+ corresponding lines) REDACTED
Code Duplication · Edited copy of a member (46 corresponding lines) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py
Code Duplication · Edited copy of a member (55 corresponding lines) REDACTED
Code Duplication · Edited copy of a member (46 corresponding lines) libs/langchain/langchain_classic/chains/base.py
Code Duplication · Edited copy of a member (41 corresponding lines) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py
Code Duplication · Edited copy of a member (41 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py
Code Duplication · Edited copy of a member (42 corresponding lines) libs/langchain/langchain_classic/agents/mrkl/output_parser.py
Code Duplication · Edited copy of a member (28 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py
Code Duplication · Edited copy of a member (51 corresponding lines) libs/partners/openai/langchain_openai/llms/base.py
Code Duplication · Edited copy of a member (139 corresponding lines) libs/langchain_v1/langchain/agents/middleware/types.py
Code Duplication · Edited copy of a member (48 corresponding lines) libs/langchain/langchain_classic/agents/agent.py
Code Duplication · Edited copy of a member (36 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py
Code Duplication · Edited copy of a member (54 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py
Code Duplication · Edited copy of a member (43 corresponding lines) libs/core/langchain_core/runnables/branch.py
Code Duplication · Edited copy of a member (40 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py
Code Duplication · Edited copy of a member (26 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py
Code Duplication · Edited copy of a member (32 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py
Code Duplication · Edited copy of a member (73 corresponding lines) libs/partners/openai/langchain_openai/embeddings/azure.py
Code Duplication · Edited copy of a member (42 corresponding lines) libs/core/langchain_core/prompts/few_shot_with_templates.py
Code Duplication · Edited copy of a member (46 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (66 corresponding lines) libs/langchain/langchain_classic/chains/question_answering/chain.py
Code Duplication · Edited copy of a member (29 corresponding lines) libs/core/langchain_core/prompts/chat.py
Code Duplication · Edited copy of a member (62 corresponding lines) libs/langchain_v1/langchain/agents/middleware/tool_selection.py
Code Duplication · Edited copy of a member (158 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
Code Duplication · Edited copy of a member (60 corresponding lines) libs/core/langchain_core/messages/ai.py
Code Duplication · Edited copy of a member (57 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
Code Duplication · Edited copy of a member (26 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py
Code Duplication · Edited copy of a member (40 corresponding lines) libs/core/langchain_core/vectorstores/base.py
Code Duplication · Edited copy of a member (26 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py
Code Duplication · Edited copy of a member (45 corresponding lines) libs/partners/fireworks/langchain_fireworks/llms.py
Code Duplication · Edited copy of a member (26 corresponding lines) libs/core/langchain_core/runnables/router.py
Code Duplication · Edited copy of a member (42 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py
Code Duplication · Edited copy of a member (30 corresponding lines) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py
Code Duplication · Edited copy of a member (29 corresponding lines) libs/core/langchain_core/runnables/configurable.py
Code Duplication · Edited copy of a member (64 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py
Code Duplication · Edited copy of a member (38 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/reduce.py
Code Duplication · Edited copy of a member (70 corresponding lines) libs/core/langchain_core/callbacks/manager.py
Code Duplication · Edited copy of a member (30 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (33 corresponding lines) libs/partners/ollama/langchain_ollama/llms.py
Code Duplication · Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/agents/agent.py
Code Duplication · Edited copy of a member (29 corresponding lines) libs/core/langchain_core/runnables/utils.py
Code Duplication · Edited copy of a member (28 corresponding lines) libs/langchain/langchain_classic/agents/chat/output_parser.py
Code Duplication · Edited copy of a member (21 corresponding lines) libs/langchain/langchain_classic/chains/llm.py
Code Duplication · Edited copy of a member (69 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py
Code Duplication · Edited copy of a member (46 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
Code Duplication · Edited copy of a member (76 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py
Code Duplication · Edited copy of a member (27 corresponding lines) libs/core/langchain_core/vectorstores/in_memory.py
Code Duplication · Edited copy of a member (34 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py
Code Duplication · Edited copy of a member (32 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/retrievers/multi_vector.py
Code Duplication · Edited copy of a member (33 corresponding lines) libs/partners/openai/langchain_openai/middleware/openai_moderation.py
Code Duplication · Edited copy of a member (17 corresponding lines) libs/langchain/langchain_classic/chains/llm_math/base.py
Code Duplication · Edited copy of a member (48 corresponding lines) libs/core/langchain_core/tracers/event_stream.py
Code Duplication · Edited copy of a member (27 corresponding lines) libs/core/langchain_core/runnables/base.py
Code Duplication · Edited copy of a member (19 corresponding lines) libs/langchain/langchain_classic/chains/llm.py
Code Duplication · Edited copy of a member (13 corresponding lines) libs/partners/openai/langchain_openai/decisions/_input.py
Code Duplication · Edited copy of a member (34 corresponding lines) libs/core/langchain_core/runnables/passthrough.py
Code Duplication · Edited copy of a member (19 corresponding lines) libs/langchain/langchain_classic/chains/router/base.py
Code Duplication · Edited copies of one member (3 members, 27+ corresponding lines) libs/partners/qdrant/langchain_qdrant/qdrant.py
We compare every finding with the previous survey's. A finding that has only moved to another line in the same file counts as the same finding, so only new findings appear here. Advisory notes from the AI model are left out, because the model words them afresh in every survey.
Fixed since the last survey: 51 findings
These 51 critical or serious findings were in the previous survey, on 25 October 2026, and are gone from this one.
Dependency Vulnerabilities · High CVE: REDACTED REDACTED
Dependency Vulnerabilities · High CVE: [GHSA redacted] REDACTED
Dependency Vulnerabilities · High CVE: [GHSA redacted] libs/partners/huggingface/uv.lock
Dependency Vulnerabilities · High CVE: [GHSA redacted] REDACTED
Rebuild cost: about €380,000 · Estimate
Cost to rebuild
€130,000 to €640,000, for 2,116 to 6,712 hours of work, about 2.6 person-years for 1 to 5 engineers
Difficulty of the problem
Standard, judged from the kind of software and how it is built. Code that solves a harder problem, such as payments or medical bookings, costs more per line to write.
Quality factor
×0.8 at a score of 62. Better code takes more work to write, so the factor is ×1.0 at a score of 70, lower below it and higher above it.
Size
Large: 184,648 lines of product code
What it is not
Not a quotation: nobody has offered to build it for that. Not a valuation: it says nothing about what the business is worth. Not a certified figure: no professional has signed it as one.
How the estimate is made: We price the hours a team would need to write this code again, at €60 to €95 an hour. Declarations and boilerplate are priced at a fast rate and logic at a slower one, and the logic is then multiplied by the difficulty of the problem and by the quality factor. The estimate can be about 30% off either way, and it moves most with the hourly rate and the difficulty. For this code, every line is priced as straight logic, which keeps the estimate on the low side.
Top priorities
The three actions that raise the score most for the work they take. The full ranked list is in the Roadmap.
1
Resolve the 7 REDACTED finding(s) in Secrets (history) — start with REDACTED, REDACTED, REDACTED.
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Replace SQLAlchemy create_all() with Alembic (`alembic revision --autogenerate` + `alembic upgrade head`) so the production schema can evolve safely and reproducibly.
Raises the score by about 4 points · Medium effort · Schema migrations
Diagnosis: what the measurements show together
Each conclusion below combines several dimensions into one point that no single dimension shows, and lists the measurements it rests on.
Where the investment is most exposed · Value at risk
This code would cost about €380,000 to build again, about 2.6 person-years of work. Its weakest lens is Production Readiness, at 53 (Adequate). Production Readiness is about whether the product is ready to run in production and to change without breaking. Because the weakest lens counts most in the score, work on Production Readiness also moves the score most.
Based on: the rebuild estimate · the Production Readiness grade · how much each lens counts
What to do: Start with the Production Readiness actions in Top priorities.
If you do one thing first · First action
Resolve the 7 REDACTED finding(s) in Secrets (history). Of all the actions in this report, it raises the score most for the work it takes: about 2 points for low effort, because it clears the 7 Secrets (history) findings. The next survey will show the change in the score.
Based on: the ranked actions in Top priorities, by score gain and effort
What hard-to-read code costs each year · Cost
Four dimensions measure how easy the code is to work in: two measure how tangled its logic is, one how much of it is copied, and one how well each part sticks to a single job. In this codebase they average 5.5 out of 10. Code at that level is slower to change than clean code, and we estimate the extra work at 6% to 14% on every change. The history of the code shows how much it changes: about 145,879 lines over the last 90 days, which is about 591,620 lines a year. At that pace, the extra work comes to an estimated 91 to 545.8 engineer-days a year, and it grows as more code changes.
How this is estimated: The number of changed lines is measured from the history of the code. The rest rests on two assumptions of our own: code scoring 8 out of 10 or more adds no extra work, and each point below 8 adds 2.5% to 5.6% to every change, never less than 2% to 5% and never more than 40% to 60% in all; and an engineer changes 150 to 400 lines in a day. The result is a range for planning, not a measurement.
Based on: Cyclomatic Complexity · Cognitive Complexity · Code Duplication · Cohesion (LCOM4) · the code's change history
What to do: Start with the files listed under Churn × Complexity Hotspots, which change often and are hard to read, because that is where the extra work is paid most often.
Architecture — module dependency graph
Project dependencies, layered top-to-bottom; arrows show direction. Any dashed red edge points upward or sideways, which only happens where the projects form a dependency cycle. A graph without cycles has none.
Architecture: which parts of the code depend on which
The code is divided into modules, groups of code that each handle one part of the product, and a module depends on another when it uses code from it. The table lists the modules both down the side and across the top, in an order where each module should only use modules listed above it. A number in a cell means the module on that row uses the module in that column, and it counts the pairs of building blocks (types) that connect them. The one thing to look for is a mark above the diagonal line. It means two or more modules use each other in a loop (a dependency cycle), so none of them can be changed, tested or released on its own.
608 modules, with 416 dependencies between them. 3 loops run through 7 of the modules, marked above the diagonal.
The table shows the 40 modules with the most connections; 568 more are left out to keep it readable.
Which modules use which. The module on each row uses the module in each column, and the number counts the pairs of types that connect them. A cell above the diagonal is part of a loop.
core.langchain_core.agents uses core.langchain_core.load.serializable, so a change to core.langchain_core.load.serializable can break core.langchain_core.agents, while a change to core.langchain_core.agents can't break core.langchain_core.load.serializable.
Position
Below the diagonal: core.langchain_core.agents uses a module listed above it, which is the healthy direction.
core.langchain_core.prompt_values uses core.langchain_core.load.serializable, so a change to core.langchain_core.load.serializable can break core.langchain_core.prompt_values, while a change to core.langchain_core.prompt_values can't break core.langchain_core.load.serializable.
Position
Below the diagonal: core.langchain_core.prompt_values uses a module listed above it, which is the healthy direction.
12→27 core.langchain_core.tools.base uses core.langchain_core.runnables.basepart of a loop✕
Connections
1 pair of types, where a type in core.langchain_core.tools.base uses a type in core.langchain_core.runnables.base.
core.langchain_core.tools.base uses core.langchain_core.runnables.base, so a change to core.langchain_core.runnables.base can break core.langchain_core.tools.base, while a change to core.langchain_core.tools.base can't break core.langchain_core.runnables.base.
Position
Above the diagonal, so it is part of a loop. Neither module can be changed, tested or released on its own until one of these dependencies is removed.
langchain.langchain_classic.chains.combine_documents.base uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.chains.combine_documents.base, while a change to langchain.langchain_classic.chains.combine_documents.base can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.base uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains.llm uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.chains.llm, while a change to langchain.langchain_classic.chains.llm can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.chains.llm uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains.sequential uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.chains.sequential, while a change to langchain.langchain_classic.chains.sequential can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.chains.sequential uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.evaluation.schema uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.evaluation.schema, while a change to langchain.langchain_classic.evaluation.schema can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.evaluation.schema uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.memory.chat_memory uses langchain.langchain_classic.base_memory, so a change to langchain.langchain_classic.base_memory can break langchain.langchain_classic.memory.chat_memory, while a change to langchain.langchain_classic.memory.chat_memory can't break langchain.langchain_classic.base_memory.
Position
Below the diagonal: langchain.langchain_classic.memory.chat_memory uses a module listed above it, which is the healthy direction.
core.langchain_core.callbacks.base uses core.langchain_core.outputs.llm_result, so a change to core.langchain_core.outputs.llm_result can break core.langchain_core.callbacks.base, while a change to core.langchain_core.callbacks.base can't break core.langchain_core.outputs.llm_result.
Position
Below the diagonal: core.langchain_core.callbacks.base uses a module listed above it, which is the healthy direction.
core.langchain_core.callbacks.base uses core.langchain_core.agents, so a change to core.langchain_core.agents can break core.langchain_core.callbacks.base, while a change to core.langchain_core.callbacks.base can't break core.langchain_core.agents.
Position
Below the diagonal: core.langchain_core.callbacks.base uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.agents.agent uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.agents.agent, while a change to langchain.langchain_classic.agents.agent can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.agents.agent uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.agents.agent uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.agents.agent, while a change to langchain.langchain_classic.agents.agent can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.agents.agent uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.map_reduce uses a type in langchain.langchain_classic.chains.combine_documents.base.
langchain.langchain_classic.chains.combine_documents.map_reduce uses langchain.langchain_classic.chains.combine_documents.base, so a change to langchain.langchain_classic.chains.combine_documents.base can break langchain.langchain_classic.chains.combine_documents.map_reduce, while a change to langchain.langchain_classic.chains.combine_documents.map_reduce can't break langchain.langchain_classic.chains.combine_documents.base.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.map_reduce uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.map_reduce uses a type in langchain.langchain_classic.chains.llm.
langchain.langchain_classic.chains.combine_documents.map_reduce uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.chains.combine_documents.map_reduce, while a change to langchain.langchain_classic.chains.combine_documents.map_reduce can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.map_reduce uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.map_rerank uses a type in langchain.langchain_classic.chains.combine_documents.base.
langchain.langchain_classic.chains.combine_documents.map_rerank uses langchain.langchain_classic.chains.combine_documents.base, so a change to langchain.langchain_classic.chains.combine_documents.base can break langchain.langchain_classic.chains.combine_documents.map_rerank, while a change to langchain.langchain_classic.chains.combine_documents.map_rerank can't break langchain.langchain_classic.chains.combine_documents.base.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.map_rerank uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.map_rerank uses a type in langchain.langchain_classic.chains.llm.
langchain.langchain_classic.chains.combine_documents.map_rerank uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.chains.combine_documents.map_rerank, while a change to langchain.langchain_classic.chains.combine_documents.map_rerank can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.map_rerank uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.refine uses a type in langchain.langchain_classic.chains.combine_documents.base.
langchain.langchain_classic.chains.combine_documents.refine uses langchain.langchain_classic.chains.combine_documents.base, so a change to langchain.langchain_classic.chains.combine_documents.base can break langchain.langchain_classic.chains.combine_documents.refine, while a change to langchain.langchain_classic.chains.combine_documents.refine can't break langchain.langchain_classic.chains.combine_documents.base.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.refine uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains.combine_documents.refine uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.chains.combine_documents.refine, while a change to langchain.langchain_classic.chains.combine_documents.refine can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.refine uses a module listed above it, which is the healthy direction.
1 pair of types, where a type in langchain.langchain_classic.chains.combine_documents.stuff uses a type in langchain.langchain_classic.chains.combine_documents.base.
langchain.langchain_classic.chains.combine_documents.stuff uses langchain.langchain_classic.chains.combine_documents.base, so a change to langchain.langchain_classic.chains.combine_documents.base can break langchain.langchain_classic.chains.combine_documents.stuff, while a change to langchain.langchain_classic.chains.combine_documents.stuff can't break langchain.langchain_classic.chains.combine_documents.base.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.stuff uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains.combine_documents.stuff uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.chains.combine_documents.stuff, while a change to langchain.langchain_classic.chains.combine_documents.stuff can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.chains.combine_documents.stuff uses a module listed above it, which is the healthy direction.
core.langchain_core.callbacks.manager uses core.langchain_core.outputs.llm_result, so a change to core.langchain_core.outputs.llm_result can break core.langchain_core.callbacks.manager, while a change to core.langchain_core.callbacks.manager can't break core.langchain_core.outputs.llm_result.
Position
Below the diagonal: core.langchain_core.callbacks.manager uses a module listed above it, which is the healthy direction.
core.langchain_core.callbacks.manager uses core.langchain_core.agents, so a change to core.langchain_core.agents can break core.langchain_core.callbacks.manager, while a change to core.langchain_core.callbacks.manager can't break core.langchain_core.agents.
Position
Below the diagonal: core.langchain_core.callbacks.manager uses a module listed above it, which is the healthy direction.
core.langchain_core.callbacks.manager uses core.langchain_core.callbacks.base, so a change to core.langchain_core.callbacks.base can break core.langchain_core.callbacks.manager, while a change to core.langchain_core.callbacks.manager can't break core.langchain_core.callbacks.base.
Position
Below the diagonal: core.langchain_core.callbacks.manager uses a module listed above it, which is the healthy direction.
core.langchain_core.tracers.base uses core.langchain_core.outputs.llm_result, so a change to core.langchain_core.outputs.llm_result can break core.langchain_core.tracers.base, while a change to core.langchain_core.tracers.base can't break core.langchain_core.outputs.llm_result.
Position
Below the diagonal: core.langchain_core.tracers.base uses a module listed above it, which is the healthy direction.
core.langchain_core.tracers.base uses core.langchain_core.callbacks.base, so a change to core.langchain_core.callbacks.base can break core.langchain_core.tracers.base, while a change to core.langchain_core.tracers.base can't break core.langchain_core.callbacks.base.
Position
Below the diagonal: core.langchain_core.tracers.base uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.base, so a change to langchain.langchain_classic.chains.base can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.base.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.llm, so a change to langchain.langchain_classic.chains.llm can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.llm.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.combine_documents.map_reduce, so a change to langchain.langchain_classic.chains.combine_documents.map_reduce can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.combine_documents.map_reduce.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.combine_documents.map_rerank, so a change to langchain.langchain_classic.chains.combine_documents.map_rerank can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.combine_documents.map_rerank.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.combine_documents.refine, so a change to langchain.langchain_classic.chains.combine_documents.refine can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.combine_documents.refine.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
langchain.langchain_classic.chains uses langchain.langchain_classic.chains.combine_documents.stuff, so a change to langchain.langchain_classic.chains.combine_documents.stuff can break langchain.langchain_classic.chains, while a change to langchain.langchain_classic.chains can't break langchain.langchain_classic.chains.combine_documents.stuff.
Position
Below the diagonal: langchain.langchain_classic.chains uses a module listed above it, which is the healthy direction.
core.langchain_core.runnables.base uses core.langchain_core.load.serializable, so a change to core.langchain_core.load.serializable can break core.langchain_core.runnables.base, while a change to core.langchain_core.runnables.base can't break core.langchain_core.load.serializable.
Position
Below the diagonal: core.langchain_core.runnables.base uses a module listed above it, which is the healthy direction.
core.langchain_core.runnables.base uses core.langchain_core.runnables.config, so a change to core.langchain_core.runnables.config can break core.langchain_core.runnables.base, while a change to core.langchain_core.runnables.base can't break core.langchain_core.runnables.config.
Position
Below the diagonal: core.langchain_core.runnables.base uses a module listed above it, which is the healthy direction.
core.langchain_core.runnables.base uses core.langchain_core.runnables.graph, so a change to core.langchain_core.runnables.graph can break core.langchain_core.runnables.base, while a change to core.langchain_core.runnables.base can't break core.langchain_core.runnables.graph.
Position
Below the diagonal: core.langchain_core.runnables.base uses a module listed above it, which is the healthy direction.
core.langchain_core.runnables.base uses core.langchain_core.tools.base, so a change to core.langchain_core.tools.base can break core.langchain_core.runnables.base, while a change to core.langchain_core.runnables.base can't break core.langchain_core.tools.base.
Position
Below the diagonal: core.langchain_core.runnables.base uses a module listed above it, which is the healthy direction.
core.langchain_core.runnables.base uses core.langchain_core.callbacks.manager, so a change to core.langchain_core.callbacks.manager can break core.langchain_core.runnables.base, while a change to core.langchain_core.runnables.base can't break core.langchain_core.callbacks.manager.
Position
Below the diagonal: core.langchain_core.runnables.base uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.base uses core.langchain_core.prompt_values, so a change to core.langchain_core.prompt_values can break core.langchain_core.prompts.base, while a change to core.langchain_core.prompts.base can't break core.langchain_core.prompt_values.
Position
Below the diagonal: core.langchain_core.prompts.base uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.base uses core.langchain_core.runnables.base, so a change to core.langchain_core.runnables.base can break core.langchain_core.prompts.base, while a change to core.langchain_core.prompts.base can't break core.langchain_core.runnables.base.
Position
Below the diagonal: core.langchain_core.prompts.base uses a module listed above it, which is the healthy direction.
core.langchain_core.retrievers uses core.langchain_core.callbacks.manager, so a change to core.langchain_core.callbacks.manager can break core.langchain_core.retrievers, while a change to core.langchain_core.retrievers can't break core.langchain_core.callbacks.manager.
Position
Below the diagonal: core.langchain_core.retrievers uses a module listed above it, which is the healthy direction.
core.langchain_core.retrievers uses core.langchain_core.runnables.base, so a change to core.langchain_core.runnables.base can break core.langchain_core.retrievers, while a change to core.langchain_core.retrievers can't break core.langchain_core.runnables.base.
Position
Below the diagonal: core.langchain_core.retrievers uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.string uses core.langchain_core.prompt_values, so a change to core.langchain_core.prompt_values can break core.langchain_core.prompts.string, while a change to core.langchain_core.prompts.string can't break core.langchain_core.prompt_values.
Position
Below the diagonal: core.langchain_core.prompts.string uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.string uses core.langchain_core.prompts.base, so a change to core.langchain_core.prompts.base can break core.langchain_core.prompts.string, while a change to core.langchain_core.prompts.string can't break core.langchain_core.prompts.base.
Position
Below the diagonal: core.langchain_core.prompts.string uses a module listed above it, which is the healthy direction.
core.langchain_core.vectorstores.base uses core.langchain_core.callbacks.manager, so a change to core.langchain_core.callbacks.manager can break core.langchain_core.vectorstores.base, while a change to core.langchain_core.vectorstores.base can't break core.langchain_core.callbacks.manager.
Position
Below the diagonal: core.langchain_core.vectorstores.base uses a module listed above it, which is the healthy direction.
core.langchain_core.vectorstores.base uses core.langchain_core.retrievers, so a change to core.langchain_core.retrievers can break core.langchain_core.vectorstores.base, while a change to core.langchain_core.vectorstores.base can't break core.langchain_core.retrievers.
Position
Below the diagonal: core.langchain_core.vectorstores.base uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.chat uses core.langchain_core.prompt_values, so a change to core.langchain_core.prompt_values can break core.langchain_core.prompts.chat, while a change to core.langchain_core.prompts.chat can't break core.langchain_core.prompt_values.
Position
Below the diagonal: core.langchain_core.prompts.chat uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.chat uses core.langchain_core.prompts.base, so a change to core.langchain_core.prompts.base can break core.langchain_core.prompts.chat, while a change to core.langchain_core.prompts.chat can't break core.langchain_core.prompts.base.
Position
Below the diagonal: core.langchain_core.prompts.chat uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts.chat uses core.langchain_core.prompts.string, so a change to core.langchain_core.prompts.string can break core.langchain_core.prompts.chat, while a change to core.langchain_core.prompts.chat can't break core.langchain_core.prompts.string.
Position
Below the diagonal: core.langchain_core.prompts.chat uses a module listed above it, which is the healthy direction.
32→34 core.langchain_core.prompts.chat uses core.langchain_core.messages.basepart of a loop✕
Connections
3 pairs of types, where a type in core.langchain_core.prompts.chat uses a type in core.langchain_core.messages.base.
core.langchain_core.prompts.chat uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.prompts.chat, while a change to core.langchain_core.prompts.chat can't break core.langchain_core.messages.base.
Position
Above the diagonal, so it is part of a loop. Neither module can be changed, tested or released on its own until one of these dependencies is removed.
core.langchain_core.prompts.prompt uses core.langchain_core.prompts.string, so a change to core.langchain_core.prompts.string can break core.langchain_core.prompts.prompt, while a change to core.langchain_core.prompts.prompt can't break core.langchain_core.prompts.string.
Position
Below the diagonal: core.langchain_core.prompts.prompt uses a module listed above it, which is the healthy direction.
core.langchain_core.messages.base uses core.langchain_core.load.serializable, so a change to core.langchain_core.load.serializable can break core.langchain_core.messages.base, while a change to core.langchain_core.messages.base can't break core.langchain_core.load.serializable.
Position
Below the diagonal: core.langchain_core.messages.base uses a module listed above it, which is the healthy direction.
core.langchain_core.messages.base uses core.langchain_core.prompts.chat, so a change to core.langchain_core.prompts.chat can break core.langchain_core.messages.base, while a change to core.langchain_core.messages.base can't break core.langchain_core.prompts.chat.
Position
Below the diagonal: core.langchain_core.messages.base uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts uses core.langchain_core.prompts.chat, so a change to core.langchain_core.prompts.chat can break core.langchain_core.prompts, while a change to core.langchain_core.prompts can't break core.langchain_core.prompts.chat.
Position
Below the diagonal: core.langchain_core.prompts uses a module listed above it, which is the healthy direction.
core.langchain_core.prompts uses core.langchain_core.prompts.prompt, so a change to core.langchain_core.prompts.prompt can break core.langchain_core.prompts, while a change to core.langchain_core.prompts can't break core.langchain_core.prompts.prompt.
Position
Below the diagonal: core.langchain_core.prompts uses a module listed above it, which is the healthy direction.
core.langchain_core.exceptions uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.exceptions, while a change to core.langchain_core.exceptions can't break core.langchain_core.messages.base.
Position
Below the diagonal: core.langchain_core.exceptions uses a module listed above it, which is the healthy direction.
core.langchain_core.messages.ai uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.messages.ai, while a change to core.langchain_core.messages.ai can't break core.langchain_core.messages.base.
Position
Below the diagonal: core.langchain_core.messages.ai uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models uses core.langchain_core.outputs.llm_result, so a change to core.langchain_core.outputs.llm_result can break core.langchain_core.language_models, while a change to core.langchain_core.language_models can't break core.langchain_core.outputs.llm_result.
Position
Below the diagonal: core.langchain_core.language_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.language_models, while a change to core.langchain_core.language_models can't break core.langchain_core.messages.base.
Position
Below the diagonal: core.langchain_core.language_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models uses core.langchain_core.messages.ai, so a change to core.langchain_core.messages.ai can break core.langchain_core.language_models, while a change to core.langchain_core.language_models can't break core.langchain_core.messages.ai.
Position
Below the diagonal: core.langchain_core.language_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.outputs.llm_result, so a change to core.langchain_core.outputs.llm_result can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.outputs.llm_result.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.prompt_values, so a change to core.langchain_core.prompt_values can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.prompt_values.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.callbacks.manager, so a change to core.langchain_core.callbacks.manager can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.callbacks.manager.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.runnables.base, so a change to core.langchain_core.runnables.base can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.runnables.base.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.messages.base.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.language_models.chat_models uses core.langchain_core.messages.ai, so a change to core.langchain_core.messages.ai can break core.langchain_core.language_models.chat_models, while a change to core.langchain_core.language_models.chat_models can't break core.langchain_core.messages.ai.
Position
Below the diagonal: core.langchain_core.language_models.chat_models uses a module listed above it, which is the healthy direction.
core.langchain_core.messages uses core.langchain_core.messages.base, so a change to core.langchain_core.messages.base can break core.langchain_core.messages, while a change to core.langchain_core.messages can't break core.langchain_core.messages.base.
Position
Below the diagonal: core.langchain_core.messages uses a module listed above it, which is the healthy direction.
core.langchain_core.messages uses core.langchain_core.messages.ai, so a change to core.langchain_core.messages.ai can break core.langchain_core.messages, while a change to core.langchain_core.messages can't break core.langchain_core.messages.ai.
Position
Below the diagonal: core.langchain_core.messages uses a module listed above it, which is the healthy direction.
At a glance — Code Health · 71% · Adequate · gated by D2, D4 ·
Findings mapped to OWASP categories; the specific CVEs/secrets are in the Security dimension cards below and findings.md (redacted only on the public version of this report).
OWASP category
Findings
Severity
A05:2025 — Injection
40
High / Critical
A03:2025 — Software Supply Chain Failures
10
High / Critical
A07:2025 — Authentication Failures
8
High / Critical
A02:2025 — Security Misconfiguration
2
Medium
Roadmap
Top priorities: Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing; Replace SQLAlchemy create_all() with Alembic (`alembic revision --autogenerate` + `alembic upgrade head`) so the production schema can evolve safely and reproducibly; Keep a changelog (e.g. Keep-a-Changelog) recording what shipped in each release.
Ranked by impact ÷ effort. "Helps" is the estimated gain on the 0–100 health score.
Do this
Helps
Effort
Dimension
Resolve the 7 REDACTED finding(s) in Secrets (history) — start with REDACTED, REDACTED, REDACTED.
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Replace SQLAlchemy create_all() with Alembic (`alembic revision --autogenerate` + `alembic upgrade head`) so the production schema can evolve safely and reproducibly.
Every finding carries one of four grades. Three say how serious it is. The fourth says this
survey could not settle it — and it is a grade, not a gap.
Critical — 49
A definite problem that already costs you something and drags the score down: a
missing authorisation check, a dependency with a known exploit, a build that does not reproduce. Failure here
tends to cause failures elsewhere.
Serious — 1300
Likely wrong, but not failing yet. It degrades
the codebase over a longer horizon and can cause failures elsewhere — not urgent this week, not something to
carry for two years either.
Minor — 120
Recorded, with no effect on how the codebase functions.
Present so the survey is complete, not because it needs doing.
Could not be resolved — 15
Something this survey could not settle
from the outside, and which could be critical or serious. Either a control was required and no
positive evidence of it exists in the repository — a backup job that nothing shows was ever restored from proves
nothing about restores — or our own analysis could not run over that part of the tree. This is not a clean
result. These are excluded from the score rather than awarded a pass, so the number on the cover neither
rewards nor penalises them: if you act on this survey without resolving them, you carry that risk yourself. Each
one is named under Limitations.
Methodology & how to trust this report
This survey is a deep, periodic assessment — run each sprint, monthly, or quarterly, taking the time to go wider and deeper than a quick check and surfacing in one coherent report what you'd otherwise piece together from a dozen separate tools. It scores deterministically: the same commit yields the same score, every run. All 52 evaluated dimensions are computed by tools and static analysis; no language model sets or judges any of them. Overall confidence is 0.9, the weighted average across measured dimensions.
Every figure here is one of two kinds, and we label which: ✓ Measured — a deterministic fact (LoC, complexity, coverage); ~ Modeled — an estimate from a stated model (cost, effort, value-at-risk), always a range with its assumptions, never a precise fact. We never present a modelled estimate as if it were measured. Perfect or absent scores carry their provenance too (ADR-0011): ✓ Tool-verified means the property itself was measured across the surface; ○ Nothing flagged means the probes came back clean — a claim bounded by what a repository can show; ⊘ Not evidenced means a working control (a tested restore, an automated rollback) showed no positive evidence — absence of evidence is not evidence of a control, so it's excluded from the score rather than awarded a spurious 10.
What we checked — 52 dimensions across the health lenses
Each chip is a dimension scored from real signals across architecture, testing, dependencies, security & compliance, documentation, git-history and code quality — in one coherent pass. A surface report typically covers a handful.
How to trust any code-health report — three questions
Can you open the finding? Real findings cite a repo-relative file and line you can open at the cited line — never an absolute scratch path. Here, 1458 of 1469 do; the remainder are repo-wide signals — a dimension-level measurement, not a single line. (Every path in this report is repo-relative by construction: paths are normalized at the producer and the report is rejected if any rooted path leaks through.)
Is there a tool behind the number? Every score below names the method that produced it: Roslyn, git or a scanner, not a narrative.
Does re-running give the same result? Run it again on the same commit and the score — and this report, byte for byte — is identical. A report whose numbers move between runs is describing the run, not the code.
This report answers yes to all three. That's the bar to hold any assessment to.
Tools & methods
The actual versions used this run (captured at analysis time) — re-run on the same commit for the identical score.
Method
Backs
Version
Evaluator
Roslyn static analysis
Complexity, cohesion, coupling, dead code, API surface, layering
What ran differently this time — a tool absent, degraded, or that fell back to an estimate. Named openly, not folded silently into the scores. A degraded run also records its exact cause in diagnostics.md.
D8 Code Coverage — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Coverage NOT MEASURED: test source is present (.py) but the built-in coverage collector has no runner for this repository's ecosystem — so this suite was never executed by it. Not scored — this is a gap in the analyzer's language coverage, not a defect in the repo.
D11 Test Reliability — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This repository declares 4 of its own test(s) unreliable. The built-in reliability runner does not support this repository's ecosystem (.py), so the suite was not re-run and no reliability score is given — these are the repository's own declarations, not our measurement.
D12 Dependency Hygiene — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Not scored — 36 shipped Python distribution(s) were read, but the outdated signal needs pypi.org, and no declaration here carries an exact pin to ask about — a floor or a range installs the newest release it admits and cannot be behind one, so this dimension's own question is only partly answered. NOT a finding that these dependencies are current or healthy.
D19 Documentation Quality — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. Each ecosystem's manifests (what makes a folder runnable or a published package) need their own proof before D19 judges its units. Until then those folders' READMEs are judged only as documents (boilerplate, structure), never counted as complete.
D21 Naming Consistency — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. PREREGISTRATION version 20's fallback (adjudication D21-sample3-v3): this rule kind was adjudicated below the 95 % precision gate, so its candidates are counted here and not published, and the score covers only the acronym-spelling and awaitable-suffix rules. The kind returns as rows only after it shows a measured precision; this says nothing about whether these names are consistent.
D22 Internal API Consistency — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. D22's deterministic call-shape rules are gated on C# first (docs/plans/deterministic-engine.md, P5): each other language is switched on only after its own concept suite and A/B gate pass. This says nothing about whether that surface is consistent.
D24 Comment Value — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Each source language's comment syntax, and the code a comment annotates in it, needs its own proof before D24 judges it. Until then those comments are left unread, not counted as clean.
AX6 Interface segregation — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check is computed over the public interfaces this run's compilations declare, and none was loaded, so it had nothing to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
AXR1 Runtime accessibility — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Render strategy: boot via DockerCompose (.devcontainer/docker-compose.yaml). compose up failed (exit 17 — an image could not be built) — failed to solve: process "/bin/sh -c uv sync --dev" did not complete successfully: exit code: 1; runtime evidence skipped.
C1 Data Protection — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These personal data controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks personal data controls.
GD1 Unfinished & placeholder code — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, F#, JavaScript/TypeScript, Dart, Ruby and Scala source only, and no C#, F#, JavaScript/TypeScript, Dart, Ruby or Scala was found, and this repository's Python is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
IC1 Incompleteness & stubs — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, JavaScript/TypeScript, Java, Dart, Ruby and Scala source only, and no C#, JavaScript/TypeScript, Java, Dart, Ruby or Scala was found, and this repository's Python is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
S1 Web-Security Posture — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These web-security controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks web-security controls.
X10 Duplicated predicate — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. 49 further occurrence(s) are not listed individually; the score already reflects all 89.
X16 Unfloored truncation loop — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, and JavaScript/TypeScript, Java, PHP, Dart, Ruby, Scala and Kotlin source only, and no C# was loaded and no JavaScript/TypeScript, Java, PHP, Dart, Ruby, Scala or Kotlin was found in this repository, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
X18 Disposal-pattern correctness — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, and JavaScript/TypeScript, Java, Kotlin, Dart, Ruby, Scala and PHP source only, and no C# was loaded and no JavaScript/TypeScript, Java, Kotlin, Dart, Ruby, Scala or PHP was found in this repository, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
X29 Per-element action decided by a fixed element — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, and JavaScript/TypeScript (Vue and Svelte components included), Java, Rust, Dart, Ruby, Scala and Kotlin source only, and no C# was loaded and no JavaScript/TypeScript, Java, Rust, Dart, Ruby, Scala or Kotlin was found in this repository, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
X5 Nullable reference types — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax and MSBuild project configuration, TypeScript source and its tsconfig files, Java source and its package and module declarations, PHP source and its PHPStan and Psalm configuration, Dart source and its pubspec language version, Ruby source and its Sorbet and Steep configuration, Scala source and its build's explicit-nulls, WartRemover and Scalafix settings, and Kotlin source only, and no C# was loaded, no TypeScript was found, and this repository's Python is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
Repo exclusion declarations (.gitattributes linguist-generated/vendored, .editorconfig generated_code): none declared — every source file was scored.
Limitations & what we did not check
We assess the repository exactly as committed, and only the repository. By design we do not reach outside the source tree: the live cloud account, the running CI/CD pipeline, the host's branch-protection and approval rules, the production configuration, or a restore actually exercised against a backup are all out of scope. That boundary is a feature, not a gap — a repo-relative, deterministic scan re-runs identically on any commit and every finding opens at a real file and line, where a live audit can neither be reproduced nor traced. The visible consequence is that controls which leave no in-repo evidence are reported as "not evidenced" and excluded from the score rather than awarded a number a static scan cannot justify.
Per-dimension blind spots
For each dimension that was measured, what a static, repo-only scan structurally cannot see — the honest edge of the measurement, not a failure of it.
D1 Cyclomatic Complexity: Cyclomatic complexity counts branches statically — it cannot tell an essential decision tree from accidental tangle, nor see complexity that lives in data or configuration (large switch-case token tables, DSL lexers/parsers, data-as-code rule tables) rather than control flow: a tokenizer's many single-character cases read as high complexity though each branch is trivial.
D2 Cognitive Complexity: Cognitive-complexity heuristics approximate how hard code is to follow; genuine domain difficulty and well-named intent that eases reading are not captured.
D3 God Classes: "God class" is sized by members and responsibilities visible in the type — a deliberately broad facade over a coherent subsystem can read the same as an accidental grab-bag. For front-end JS the file-length check is cohesion-aware (a single-responsibility module — one class/IIFE — earns a 3× threshold), but cohesion is approximated from top-level declarations, not true dependency structure.
D4 Code Duplication: Duplication is token-similarity — an in-process token-stream comparison over sliding windows, with type-aware normalization — so it finds copy-paste, not semantic duplication expressed differently. Committed machine-written code (scaffolded migrations, designer/codegen output, protobuf/OpenAPI stubs, model snapshots) is EXCLUDED — its repetition is the tool's, not the team's — so the score reflects hand-written duplication only.
D5 Coupling: Coupling is measured between projects/assemblies — runtime coupling through DI, reflection, messaging or shared databases is invisible to a static reference graph.
D6 Cohesion (LCOM4): LCOM4 cohesion is syntactic — it infers connectivity from which methods touch which fields/methods by name, not from real runtime behaviour or intent.
D13 REDACTED Scanning: REDACTED detection is signature- and entropy-based on the current tree — a secret that does not match a known pattern, or one already rotated, will not be flagged (a clean scan is "nothing matched", not "no secrets exist").
D14 License Compliance: License compatibility is checked against declared package metadata and a policy — mislabelled or missing license metadata, and obligations that depend on how you distribute, are not resolved here.
D15 Churn × Complexity Hotspots: Churn hotspots come from git history — a freshly imported or squashed repository has no churn signal, and recent rewrites can mask a historically risky file.
D16 Bus Factor: Bus-factor is a time-decayed model of commit attribution (who has recently, repeatedly worked a file), not comprehension — pairing, review and reading-without-committing spread knowledge it can't see; bot commits and shared accounts still distort it.
D17 Explicit Debt: Acknowledged-debt signals (TODO/FIXME, suppressions, dead code) are textual — undocumented debt that nobody marked, and debt that lives in design rather than annotations, is invisible. Committed machine-written code (scaffolded migrations, designer/codegen output, generated stubs) is excluded — it is never the team's dead code to delete.
D19 Documentation Quality: Documentation quality publishes two things only: a runnable or packaged unit with no example, and a multi-project root README that maps none of its parts. It does not judge clarity, and its other checks (overview, licence, boilerplate, structure, empty sections, XML-doc coverage) are withheld after adjudication: their candidates are counted in the card's gaps, not shown as rows. A false statement in a document is M4's; units are .NET projects only.
D20 ADR Quality: ADR quality checks the structure of the decision records present: it cannot know about decisions made and never recorded, and it does not judge how well a record argues its case. Records in a language the section lexicon does not cover are not evaluated.
D26 Project Cohesion: Project focus is sized from members/namespaces per project — a project that is broad by deliberate design reads the same as one that has sprawled.
D27 Navigability: Indirection/navigability is structural — it measures hops to follow a call, not whether that indirection buys real flexibility or just ceremony.
D28 Secrets (history): Secret-history scanning sweeps the git log for known patterns — a secret that predates the available history, or never matched a signature, is not found (clean means "nothing matched in the history we can see").
D29 Static Analysis (SAST): SAST findings are pattern-based (semgrep) — it finds classes of bug it has rules for; logic flaws, auth/authorization gaps and issues needing runtime context are out of reach (and clean means "no rule matched").
D30 Dependency Vulnerabilities: CVE matching depends on accurate package/version metadata and on the advisory databases — a vulnerability with no published advisory, or in code not declared as a dependency, is not seen. Coverage needs a RESOLVED graph: an unpinned requirements.txt, or a pom without a resolved build, yields partial coverage rather than a clean verdict. An ecosystem the analyzer cannot scan is reported as unmeasured, never as clean.
D31 IaC & Container Security: IaC scanning checks Dockerfiles/Terraform/Kubernetes against best-practice rules — it cannot see the live cloud account, runtime configuration, or drift between the committed config and what is actually deployed.
D34 Knowledge Freshness: Freshness is decayed commit RECENCY, not comprehension — code read often but rarely committed reads as orphaned, and stable code that genuinely needs no changes is penalised the same as forgotten code; bot/squash commits distort it like the bus factor.
D35 Change Coupling: Change coupling is co-change in COMMITS — files split across separate commits, or coupled only through a shared config/build step, read as uncoupled, and a sweeping commit (rename/format) is excluded so it doesn't couple everything. It shows that files change together, not WHY: a high coupling can be a healthy cohesive pair as readily as a hidden leak.
D43 Malicious Dependencies: Only packages some vulnerability database has already NAMED as malicious are seen — a compromise published in the last hours, or never reported at all, is invisible here, and this dimension reading 10 is not evidence that a dependency is trustworthy. There is no typosquat or dependency-confusion analysis: a package nobody has reported is simply absent from the feeds. Coverage is the dependency scan's: an ecosystem that could not be scanned is disclosed as unmeasured, never as clean.
D44 Platform End-of-Life: The support table is FROZEN, so it goes out of date by losing RECALL: a release that ended support after the table was written is missed until the table is refreshed, and this dimension reading 10 is not evidence that a platform is current. Only platforms the repository DECLARES in a place this pass reads are seen — a runtime named only in a Dockerfile (D31's subject), in a CI workflow (D29's), or in a file this pass does not parse (go.mod, a Gemfile ruby directive) is invisible here, which is why a repository declaring none of them abstains rather than scoring. Only frameworks with a PUBLISHED support policy are tracked: React, Flask and Express publish none, so their age cannot be judged and their absence from a report is not a statement that they are supported.
AX10 Code composition: Role is inferred from namespace/folder convention, not semantics — a domain concept living in a folder named "Services" reads as application, and the split is lines-of-code, not business value. The business-logic-share score is a SOFT, FLOORED signal: it contributes to the Architecture lens but is floored at the Critical gate, so an infrastructure-heavy design (a gateway, an ETL, a driver) is legitimately low without being nuked to zero.
P4 Deployment & Rollback: Approval/branch-protection rules live in repository settings the scan cannot see — only their in-repo evidence (config files, workflows) is checked, so a control enforced purely in the host's settings reads as "not evidenced".
P6 Release Hygiene: Rollback/observability controls are inferred from repo artefacts (pipelines, dashboards-as-code) — controls configured in external tooling, with no in-repo trace, cannot be credited.
What it measures: How tangled the control flow is — methods with many branches are hard to test and change.
Method: Cyclomatic complexity per method (1 + decision points), computed exhaustively across production source; test projects separated by convention. Deterministic.
+ 136 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 4 bodies over 60 down to 60 or less in Cyclomatic Complexity — start with chat_models._format_messages (cyclomatic 95), factory.create_agent (cyclomatic 78), utils.convert_to_openai_messages (cyclomatic 77). — This score is capped by its worst body, so a finding fixed alone moves it by almost nothing — the next one down takes its place. Refactoring these 4 together lifts Cyclomatic Complexity from 6.1 to about 6.5/10, projected with the scoring formula itself and assuming each lands exactly at 60; a cleaner split scores higher.
Detailed fixes: d1_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How hard the code is for a person to follow, beyond raw branching.
Method: Cognitive complexity per method (Sonar-style nesting-penalized score), computed exhaustively over production code, excluding test projects. Deterministic.
+ 268 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 1 body over 240 down to 240 or less in Cognitive Complexity — start with chat_models._format_messages (cognitive 278). — Refactoring it lifts Cognitive Complexity from 2.3 to about 2.6/10.
Detailed fixes: d2_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D3 · God Classes8.9 / 10Strong✓ Tool-verified
What it measures: Over-large classes that try to do too much ("god classes").
Method: God-class detection by line and method-count thresholds per logical type (partial classes unified), filtered for generated code and registration/contract false positives. Deterministic.
Resolve the 39 FileTooLong finding(s) in God Classes — start with REDACTED (8), REDACTED (7), vectorstores.py (2). — One of this dimension's main actionable groups (39 warning-level).
Resolve the 6 TooManyMethods finding(s) in God Classes — start with REDACTED (3), REDACTED, core.py. — One of this dimension's main actionable groups (6 warning-level).
Detailed fixes: d3_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D4 · Code Duplication4.0 / 10Weak✓ Tool-verified
What it measures: How much of the production code is copy-pasted: the share of production lines inside a reported copy (every copy of a duplicated block or of an edited member, each line once), 10 at none and 0 at a quarter of the lines.
Method: Code duplication via token-stream sliding windows with type-aware normalization (locals masked, type names preserved), scored on the share of production lines inside a reported copy (each line once; 10 at none, 0 at a quarter). Deterministic.
362 duplicated block group(s) detected. 15.1 % of the production lines (27,897 of 184,648) are in a reported copy. A further 333 rows report members as variants of one another; the share counts each copied line once, however many rows cite it. 72 of the 695 are in trees this repository does not ship — vendored, example/demo, project-template, fixture and benchmark code — and are ranked below the shipped groups rather than excluded from them: the duplication there is real and is still counted in this dimension's score. The dimensions that publish a production-file census leave those trees out of theirs, so this count is deliberately drawn over the wider population.
+ 252 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 14 Duplicated block (15 lines × 2) finding(s) in Code Duplication — start with REDACTED (4), openai_moderation.py (3), ai.py. — One of this dimension's main actionable groups (14 warning-level).
Resolve the 14 Duplicated block (8 lines × 2) finding(s) in Code Duplication — start with REDACTED (4), REDACTED (3), summary_buffer.py. — One of this dimension's main actionable groups (14 warning-level).
Resolve the 13 Edited copy of a member (26 corresponding lines) finding(s) in Code Duplication — start with vectorstores.py (2), REDACTED (2), REDACTED (2). — One of this dimension's main actionable groups (13 warning-level).
Detailed fixes: d4_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D5 · Coupling9.6 / 10Stronggated by 1 serious finding✓ Tool-verified
What it measures: Whether volatile projects sit underneath others that depend on them (so their churn ripples upward), and whether project dependencies form cycles. A widely-depended-on but stable shared/kernel project is healthy, not penalised.
Method: Dependency cycles via elementary-DFS over real .csproj references, plus Martin instability (afferent/efferent) per project. Exhaustive over the reference graph, deterministic.
Coverage: Exhaustive · type-level: afferent/efferent coupling + cycles computed over every production type — the population is all types, not a name convention.
22 production modules (Python), 0 dependency cycle(s), 0 unstable depended-on module(s). Read from the build's own module declarations; 1 module(s) off the main sequence.
Off the main sequence: langchain-core
What to do
Resolve the 1 Off the main sequence finding(s) in Coupling. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d5_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether a class's methods are focused on a single responsibility.
Method: LCOM4 cohesion per production class with at least two methods: connected components of methods sharing state or calls, computed syntactically. Deterministic, not a proxy.
Coverage: Exhaustive · type-level: LCOM4 cohesion computed over every production class — the population is all types, not a name convention.
Resolve the 5 Low cohesion finding(s) in Cohesion (LCOM4) — start with REDACTED (3), REDACTED (2). — One of this dimension's main actionable groups (5 warning-level).
Detailed fixes: d6_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any secrets (keys, tokens, passwords) have leaked into the code.
Method: In-process native secret scanner (entropy plus signature patterns) across all tracked files; no external tool. A clean result is a measured 10, not no-data zero. Deterministic.
What it measures: Whether the licenses of third-party packages are compatible with your policy.
Method: Third-party package licenses resolved from declared package metadata and checked against the configured policy (allow/deny/copyleft). Deterministic; clean = no incompatible license found at metadata depth.
0 of 138 shipped Python distribution(s) use a banned license. Licences were resolved from PyPI over the distributions a consumer installs — this repository's 36 declared runtime requirement(s) closed transitively over each distribution's published `requires_dist` (102 reached that way). Requirements it states ONLY under an extra, a PEP 735 dependency group, a Poetry dev group or a dev-named requirements file are excluded: pip does not install any of them for a consumer. ★ This repository commits no dependency lockfile that this pass reads, so each licence is the one PyPI publishes for the distribution's CURRENT release rather than for a pinned version. 6 of them publish no licence on PyPI this pass can read; that is missing data, not a violation, and none of them is charged. This repository publishes itself under MIT, which is its own choice and is not judged here.
What it measures: Files that change often and are also complex — the riskiest hotspots.
Method: Per production file churn times cyclomatic complexity over a rolling window, computed from git and Roslyn/JS/Razor analysis. Exhaustive, deterministic per commit date.
Resolve the 13 Hotspot finding(s) in Churn × Complexity Hotspots — start with REDACTED (3), REDACTED (2), _compat.py (2). — One of this dimension's main actionable groups (13 warning-level).
Detailed fixes: d15_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D16 · Bus Factor9.8 / 10Exemplary✓ Tool-verified
What it measures: Whether knowledge is concentrated in too few people (the "bus factor").
Method: Living knowledge per author via time-decayed commit attribution (6-month half-life, focus weighting) across largest source files. Deterministic, avoids blame's mechanical-refactor false positives.
7 source file(s) have their living knowledge concentrated in one author (≥90% of recent, decayed contribution). The largest is libs/model-profiles/langchain_model_profiles/_summary.py. Counted over 446 of the 1766 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Off-boarding risk: anonymized user #1
Further sole-owners (lower concentration)
✓ On the Gold path — maintain.
Detailed fixes: d16_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Acknowledged debt left in the code — TODOs, dead code, suppressed warnings.
Method: Roslyn syntactic debt markers (suppressions/TODO/FIXME/HACK/empty-catch/commented-code/Obsolete) plus SymbolFinder dead-code analysis; weighted-debt-per-KLoC density deducted 2.0x per unit. Deterministic, exhaustive.
82 deducted task-comment markers across 184648 LoC (0.0/KLoC) → score 9.9. Task comments only: this repository's language is read without a compiler, so D17's suppression, dead-code and commented-out-code arms did not run and this score counts fewer marker kinds than a .NET repository's would.
Resolve the 82 TodoComment finding(s) in Explicit Debt — start with REDACTED (10), REDACTED (6), content.py (5). — One of this dimension's main actionable groups (82 warning-level).
Detailed fixes: d17_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the project's documentation is clear, complete, and useful.
Method: Every README, docs/ document and root guide parsed by its markup and measured in Unicode letters. Published: a runnable or packaged .NET project whose README (or a document it links, or a root guide) shows no example, and a root README naming none of three or more projects. Overview, licence, boilerplate, wall-of-text, empty-section and XML-doc rows are measured and withheld (counted in gaps) after adjudication. Deterministic, exhaustive, advisory.
1 of 1 documentation facets pass in full. 26 document(s) read across 1 unit(s).
✓ On the Gold path — maintain.
Detailed fixes: d19_recommendation.md.
Do you agree with this assessment?
D20 · ADR Quality0.0 / 10Critical✓ Tool-verified
What it measures: Whether architecture decisions are recorded well (context, decision, consequences).
Method: Every ADR read by its section structure: nine located rules (a missing Decision, Context or Consequences section, a stale status, two records deciding the same question, a dangling supersede link, a number-only title, a single option, no named cost, no status where the log uses one, no enforcement field where the log adopted one), each a fixed deduction from 10; the score is the mean over evaluated records. Deterministic, no model. Advisory.
Resolve the 1 No ADRs found finding(s) in ADR Quality — start with REDACTED. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d20_recommendation.md · top locations in Appendix A, every location in findings.md.
3 of 22 build units (Python, checkout) flagged as possibly oversized/incoherent.
Projects may be oversized for their cohesion
What to do
Resolve the 1 Projects may be oversized for their cohesion finding(s) in Project Cohesion. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d26_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How far you must trace to follow a call — low indirection and co-located slices read easier.
Method: Call indirection (interface hops, cross-namespace calls, slice-locality scaled) over a sampled set of method invocations, size-aware baseline. Sampled; confidence discounted by symbol-resolution gaps. C# also names each pass-through layer (a class whose every public method only forwards its own parameters to one collaborator) as a located finding; the score is not affected.
Coverage: Slice locality from the first namespace segments, SAMPLED (≤400 methods) — not exhaustive.
82 % of calls cross a namespace and 0 % go through an interface, but 100 % of collaborators are co-located — so a call's collaborators sit together and tracing stays easy. Baseline: small — navigation cost is tolerated.
What it measures: Whether any secrets were ever committed — scanned across the full git history, not just now.
Method: REDACTED scan via TWO gitleaks detect passes in an isolated checkout — the full git history, then a second --no-git pass over the working tree as it stands — merged and de-duplicated by (rule, file, line); each match flagged High. Both invocations are recorded in the audit trail. Exhaustive; when the tool is absent, or when its output cannot be parsed into the expected shape, the dimension is WITHHELD as an explicit measurement gap on our side — unscored and excluded from the lens, never a hedged middling score.
7 finding(s): 0 critical, 7 high, 0 medium, 0 low. Remediation for historically-committed secrets is credential rotation — they remain in history regardless of later deletion.
REDACTED
REDACTED
What to do
Resolve the 7 REDACTED finding(s) in Secrets (history) — start with REDACTED, REDACTED, REDACTED. — One of this dimension's main actionable groups (7 issue-level).
Resolve the 1 Rotate the exposed credentials finding(s) in Secrets (history). — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d28_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Real static-analysis (SAST) findings — likely security bugs in the code, any language.
Method: Polyglot static analysis via semgrep across the repo using the pinned, image-baked p/security-audit + p/owasp-top-ten rulesets (no scan-time registry fetch); severity rules (ERROR/WARNING/INFO) map to a full-band severity-weighted score. Exhaustive, deterministic; degrades on parse failure.
Coverage: semgrep pattern rules over all files — exhaustive for the rule set, blind to classes of bug without a rule (clean = no rule matched).
40 finding(s): 0 critical, 33 high, 7 medium, 0 low. semgrep hit a parse error in 1 file(s) — `libs/partners/openrouter/langchain_openrouter/data/_profiles.py` — so no absence of findings in them is evidence of anything, and nothing in them was analysed. Fix the syntax error (or exclude the file deliberately) and re-scan to cover them. Separately, one or more rules could not re-parse an embedded snippet in 5 file(s) (e.g. a workflow `run:` block read as shell). Those files WERE scanned and their other rows are unaffected; only those rules' view of those snippets is missing.
REDACTED
REDACTED
REDACTED
REDACTED
REDACTED
+ 2 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 22 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (22). — One of this dimension's main actionable groups (22 issue-level).
Resolve the 5 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (5). — One of this dimension's main actionable groups (5 issue-level).
Resolve the 3 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (2), REDACTED. — One of this dimension's main actionable groups (3 issue-level).
Detailed fixes: d29_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any dependency has a known published vulnerability (CVE), direct or transitive, in ANY ecosystem the repository declares — Dart pub, Elixir and Erlang via Hex, Go modules, Java and Kotlin via Maven/Gradle, JavaScript/npm, .NET/NuGet, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift.
Method: Dependency-CVE scan across every ecosystem the repository declares, scored ONCE. Three sources are unioned and deduplicated by advisory identity (rule id + alias closure, CVE<->GHSA) scoped to package+version, keeping the worst severity: `osv-scanner --recursive` over osv.dev for Dart pub, Elixir/Hex (and Erlang, whose `rebar.lock` syft first converts to a CycloneDX SBOM the scanner reads, with rows attributed back to the lock), Go, Java and Kotlin via Maven/Gradle (and Scala, whose sbt build's pinned direct declarations are written into a CycloneDX SBOM the scanner reads, with rows attributed back to the build file), npm, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift; `trivy fs --scanners vuln` for npm lockfiles; and `dotnet list package --vulnerable --include-transitive` for NuGet (with per-advisory collapse of the project x target-framework fan-out), plus a DECLARED-dependency arm that resolves a published gem's gemspec against rubygems.org where no Gemfile.lock is committed. `SeverityScore(c,h,m,l, normalizer 8.0)`. NotApplicable only when NO ecosystem is readable; if any applicable ecosystem could not be scanned the findings are REPORTED and the score is withheld. Supersedes the npm and OSV arms, retired 2026-09-05. Advisory since rubric-2026.11.2 (CAI decision 0006): every row is a match against a vulnerability database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
Resolve the 3 High CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (3). — One of this dimension's main actionable groups (3 issue-level).
Resolve the 1 Critical CVE finding(s) in Dependency Vulnerabilities — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 2 Medium CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (2). — One of this dimension's main actionable groups (2 warning-level).
Detailed fixes: d30_recommendation.md · top locations in Appendix A, every location in findings.md.
Resolve the 2 Medium IaC finding(s) in IaC & Container Security — start with REDACTED (2). — One of this dimension's main actionable groups (2 warning-level).
Detailed fixes: d31_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether anyone still has living knowledge of each file, or it has been orphaned — last understood long ago by someone now gone quiet. The sibling of the bus factor: D16 asks who owns it, D34 asks whether anyone still knows it.
Method: File orphaning as total living-knowledge decay below one focused-commit's worth within a year, computed per-file from the D16 decay model. Exhaustive, deterministic over fixed history.
58 of 446 significant source file(s) are orphaned — their living knowledge has decayed to nothing, so no one currently understands them. The largest is libs/langchain/langchain_classic/chains/constitutional_ai/principles.py. Counted over 446 of the 1766 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Resolve the 1 Orphaned knowledge finding(s) in Knowledge Freshness — start with principles.py. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 57 Orphaned file finding(s) in Knowledge Freshness — start with REDACTED (8), __init__.py (5), prompt.py (5). — One of this dimension's main actionable groups (57 recommendation-level).
Resolve the 1 Further orphaned files (smaller) finding(s) in Knowledge Freshness. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d34_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether files that change together actually belong together — pairs that repeatedly co-change in git history despite having no explicit code dependency, surfacing the hidden/logical coupling (and boundaries in the wrong place) a static scan can't see.
Method: Pairwise co-occurrence over the per-commit file sets in git history (production source only — tests and generated dropped): Degree-of-Coupling = shared ÷ min individual revisions, reported above noise floors (each file ≥10 revisions, ≥5 shared commits, ≥50% strength); sweeping commits excluded. Deterministic over fixed history.
Coverage: Population: PRODUCTION source files only — test and generated files are dropped before pairing, so a class co-changing with its own test (trivially ~100%) can't drown the real production↔production coupling. Pairs ranked by Degree-of-Coupling. A non-source file is never a coupling PARTICIPANT either: documentation, schemas, config and data files are dropped with the rest, so a code↔docs pair — a command and the reference page that restates it — is not reported however strongly the two co-change; nor is coupling that runs THROUGH a build step or config file.
Resolve the 4 Change coupling finding(s) in Change Coupling — start with extraction.py (2), context_editing.py, factory.py. — One of this dimension's main actionable groups (4 warning-level).
Resolve the 1 Change coupling clique finding(s) in Change Coupling — start with REDACTED. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d35_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the build pipeline provides supply-chain integrity — generated provenance/attestation, signed artifacts (cosign/sigstore), an SBOM, and pinned build actions. Presence of the configuration, not a runtime guarantee.
Method: Supply-chain provenance/signing read deterministically from CI/build config (.github/workflows, .gitlab-ci.yml, azure-pipelines, Jenkinsfile, .circleci) + the release surface: four signals — generated provenance/attestation (SLSA/in-toto/actions-attest), artifact signing (cosign/sigstore/gitsign), an SBOM (syft/sbom-action/*.spdx.json/*.cdx.json), and SHA-pinned build actions — scored 10·present/denom. NotApplicable without a build pipeline. Detects configuration presence, not runtime enforcement.
What it measures: Whether any dependency the repository declares is published as MALICIOUS rather than merely vulnerable — a package that is an attacker's work, in any ecosystem osv-scanner reads. Reported apart from D30 because the answer is binary: there is no safe version to upgrade to, and the fix is to remove the package and rotate every credential it could have read.
Method: The same dependency scan D30 reads, partitioned on the scanner's own classification rather than rescanned: a row is MALICIOUS when its id is in the `MAL-` space (the ossf/malicious-packages feed) OR its `database_specific.cwe_ids` carries `CWE-506` ("Embedded Malicious Code"). Both channels are structural; the summary text is deliberately NOT read, because a malicious-package record whose summary says only "Critical severity vulnerability" is a real shape ([GHSA redacted]) and a text matcher misses it. Scored BINARY: any surviving row is 0, whatever its severity and however many CVEs sit beside it — a hostile dependency is not a quantity. Applicability and degradation are D30's: NotApplicable only when no ecosystem is readable, and an unscannable ecosystem degrades rather than reading clean. Advisory since rubric-2026.11.2 (CAI decision 0006): the malicious-package feed is a database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
What it measures: Whether anyone still ships security patches for the platform this repository RUNS ON — the runtime it pins and the framework majors its own constraints hold it to. Separate from D12 because the question differs: a current Django on an end-of-life Python is perfectly up to date and completely unsupported, and the fix is a migration rather than a version bump. What the repository says it merely SUPPORTS is never charged.
Method: End-of-life PLATFORM read from the repository's own declarations and graded against a FROZEN, dated table of vendor support dates — no network, no feed, no API, so this dimension answers identically inside a closed scan fence. Two subjects: a RUNTIME the project pins (a single or all-end-of-life TargetFramework, a .nvmrc or .python-version, a requires-python CAP) and a FRAMEWORK major a dependency constraint cannot move off (a caret, tilde or exact version; `vue@^2.7.16` pins Vue 2). A FLOOR is deliberately never charged — `requires-python = ">=3.8"` states what a package SUPPORTS, not what it runs on — and a multi-target project is charged only when EVERY target is out of support. Runtime 4.0/product capped 8.0, framework 1.5 capped 4.5. The table is safe to freeze because a statement about support that ended in the past cannot become false: it loses recall as it ages, never precision, and a test asserts every entry predates the freeze date. Disjoint from D31 (a container image's OS layer) and D29 (the toolchain a CI workflow installs). Abstains when the repository declares no platform this pass reads — never scores it clean.
0 end-of-life runtime(s) and 0 end-of-life framework(s), read from 0 platform declaration(s) and 36 dependency declaration(s). This dimension reads what the repository says about ITSELF — a pinned target framework, a version file, a capped requires-python, a Rust toolchain pin, a framework major a constraint cannot move off. A FLOOR is deliberately never charged: `requires-python = ">=3.8"` states what the package SUPPORTS, not what it runs on, and a well-maintained library declares exactly that while running its own CI on a current release. The end-of-life facts are FROZEN and dated, so this dimension needs no network and answers identically inside a closed scan fence; as the table ages it loses recall and never precision, because a statement about support that ended in the past cannot become false. The OS layer of a container image is D31's question and the toolchain a CI workflow installs is D29's; this row is neither.
Other · Architecture — How the codebase splits by code ROLE — domain, application, infrastructure, test, generated. The significance map behind the knowledge/coupling weighting, and a DDD signal in its own right: a thin domain core under fat infrastructure is the anemic-domain smell, quantified. How each file's role is decided, because the split is only as good as that: a generated name or a build-output tree makes it Generated, a test project makes it Test, and otherwise the file's NAMESPACE and PATH words are matched against fixed vocabularies in a fixed ORDER — domain, then infrastructure, then application — so a file whose words hit two layers is counted under the earlier one. A production file matching none of them counts as application, so that share reads 'application or unclassified' rather than a measured application layer. Roles come from naming convention, never from what the code does. On this repository the split was taken from the source tree on disk rather than from a loaded .NET workspace, so a file's role is decided by its PATH segments alone — no declared namespace was available to add to the evidence — and generated output is excluded from the census entirely rather than counted as a generated share.
Method: Roslyn line-count by code ROLE: every source file classified Domain/Application/Infrastructure/Test/Generated by namespace + path convention (the shared CodeRoleClassifier), then significant lines summed per role. Deterministic; the advisory score is the business-logic (domain+application) share of production code.
Coverage: Population: ALL source files, each bucketed into ONE of five roles (Domain/Application/Infrastructure/Test/Generated) by namespace + path convention — a file whose layer isn't named in the convention falls to Application (the neutral default), and the split is line-count, not semantic depth or business value.
Other · Architecture — Whether the project-reference graph is acyclic (cycles block independent build/deploy and signal eroding boundaries).
Method: Project reference cycles via elementary-DFS over real .csproj references, using the engine shared with D5/D7; cyclic versus acyclic. Exhaustive, deterministic.
Other · Architecture — Whether dependencies point inward (Domain ← Application ← Infrastructure/Web) — the clean-architecture dependency rule, checked across the project graph.
Method: Layer violations by name-segment inference (Domain/Core to Application to Infrastructure/Web) over the project-reference graph. Exhaustive over all projects, deterministic.
Maturity · Maturity — Whether the repository and its projects have a README, and whether it is substantive.
Method: Filesystem scan: README presence, word count, and headings for depth; git history for staleness. Exhaustive across root and project dirs, deterministic.
What to do
Add a build/run (quick start) section to the root README — the first thing a newcomer needs.
Explain in the README how to run the tests. Add a section called Testing to the README in the repository's top folder, saying how to run the test suite.
Maturity · Maturity — Whether key decisions (ADRs) and the high-level shape (C4/diagrams) are written down.
Method: Filesystem scan: ADR folder/naming conventions or content, plus Mermaid/PlantUML/C4/architecture.md discovery. Exhaustive, deterministic.
No Architecture Decision Records found — no conventional ADR directory, no numbered `NNNN-title` documents in any markup this check reads, and nothing ADR-shaped by content. Design rationale recorded elsewhere (a design-notes tree, a mailing list, pull-request discussion) is not visible to this check and is not re-findable per decision, so a future maintainer cannot ask why one choice was made and get an answer.
What to do
Record your significant design decisions. Write one short document per decision, giving its date, the situation, the decision and its consequences, and keep them together with your other design documents. A docs/adr folder with each file named by number and title is the easiest place to find them.
Maturity · Maturity — Whether the repository is organised deliberately: production code and tests are set apart in a way its ecosystem or the repository itself declares.
Method: Filesystem scan: src/test folder separation and namespace-prefix consistency (majority RootNamespace agreement). Exhaustive across projects, deterministic.
Readiness · Readiness — Whether an automated pipeline builds and tests every change.
Method: Filesystem scan: CI workflow files (.github/workflows, .gitlab-ci.yml, etc.) for build and test stages. Exhaustive, deterministic.
Do you agree with this assessment?
P10 · Library API & versioning10.0 / 10Exemplary○ Nothing flagged
Readiness · Readiness — For a library: a deliberate (small) public API surface and explicit semantic versioning so consumers can depend on it safely.
Method: Roslyn scan: public API surface area and semantic-versioning markers (SemVer attributes, changelog entries) for libraries; off .NET, a library is the ecosystem's publication act (an npm package that is not private and names an entry point, a PyPI distribution with a build system, a Rust library crate, a Maven/Gradle module that publishes, a Go module with no package main, a gemspec, a Composer library, a SwiftPM library product, a pub.dev or Hex package), its surface is the share of types the language's code model records as public (Rust, Swift, Java, Kotlin, Go, Dart; not measured where the model records no type visibility or, as in TypeScript, only module-level export), and its version is read from the manifest, a semver CHANGELOG, release tooling or semver git tags. Exhaustive, deterministic.
Do you agree with this assessment?
P2 · Observability6.8 / 10Strong✓ Tool-verified
Readiness · Readiness — Whether the code is diagnosable in production — structured logging, tracing/metrics, health checks.
Only 12/13 runnable modules use logging (modules with no entry point or server are excluded — they are libraries a runnable module hosts). Silent: `libs/model-profiles`.
What to do
Extend structured logging to the remaining runnable modules so everything you run is diagnosable in production.
Readiness · Readiness — Whether SAST, secret/dependency scanning and performance benchmarking are wired in (presence, not runtime).
Method: Filesystem scan: SAST configuration, dependency-update automation, secret scanning, and a benchmark harness or benchmark step — in this repository's own ecosystem. Exhaustive, deterministic.
No static application security testing detected. For this repository's stack, add bandit, `semgrep --config=p/python`, or CodeQL's python pack as a CI step. What was searched, so you can tell an absence from a miss: the 27 CI workflow file(s) in this repository, and the scanner and linter configuration checked in beside them. A scan that runs outside CI, one configured in your forge's web UI rather than in a committed file, or a tool whose name is none of those this check carries, is not seen — if that is your case the row is wrong, and saying so is more useful than adding a second scanner. — .github/workflows/block_fork_main_prs.yml:18
What to do
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Add gitleaks/trufflehog in CI to block PRs that introduce committed secrets.
Readiness · Readiness — Whether releases are automated and safely reversible (probes, rolling updates, approval gates) — from manifests/pipeline files, not the live environment.
Method: Filesystem scan: deployment manifests/IaC (K8s YAML, Helm, Terraform) for rolling updates, probes, approval gates, migration hooks. Exhaustive, deterministic.
What to do
Make sure a person approves each release. The release job names an environment, but its approval rules live in the code host's settings, where we can't see them. Check that a reviewer must approve each release, or publish releases as drafts first, so a bad build can be stopped before anyone downloads it.
Readiness · Readiness — Whether releases are traceable — a maintained changelog and explicit version stamping.
Method: Filesystem scan: changelog file presence and version tags in csproj or git tags. Exhaustive, deterministic.
No CHANGELOG/HISTORY/RELEASES file — what shipped when isn't easy to reconstruct for support or audit. (Versioning/tagging makes releases traceable, but a changelog records the what.)
What to do
Keep a changelog (e.g. Keep-a-Changelog) recording what shipped in each release.
Do you agree with this assessment?
P8 · Schema migrations3.0 / 10Weak✓ Tool-verified
Readiness · Readiness — Whether database schema changes go through versioned migrations rather than being auto-created from the model at startup.
Method: Roslyn scan: EF Core DbContext for a versioned migrations directory versus bare EnsureCreated usage; off .NET, a file scan of dependency manifests, migration histories (Flyway, Liquibase, Alembic, Django, Rails, Prisma, TypeORM, Knex/Sequelize, golang-migrate, goose, Laravel, Doctrine, Diesel/sqlx) and schema auto-create in production source or config. Exhaustive, deterministic.
SQLAlchemy create_all() builds the schema from the model at startup and keeps no migration history, so there is no reviewed, repeatable upgrade path for an existing production database — a renamed column is dropped and re-added rather than migrated. Adopt Alembic (`alembic revision --autogenerate` + `alembic upgrade head`), so every schema change is a versioned file applied the same way in every environment. — libs/langchain/langchain_classic/indexes/_sql_record_manager.py:154
What to do
Replace SQLAlchemy create_all() with Alembic (`alembic revision --autogenerate` + `alembic upgrade head`) so the production schema can evolve safely and reproducibly.
Readiness · Performance — Whether the code protects its performance with benchmarks — a benchmark suite, allocation/memory measurement, and (ideally) a CI gate. Presence is credited as a bonus, never a deduction.
Method: Repo + source scan: BenchmarkDotNet referenced (csproj/source), [Benchmark]/[MemoryDiagnoser] attribute counts, and a benchmark step in CI; off .NET, the same ladder over Go testing.B, Rust criterion/#[bench]/divan, JMH/kotlinx-benchmark, pytest-benchmark/asv/pyperf, tinybench/mitata/vitest bench/benchmark.js and Swift package-benchmark — scored as a bonus ladder (absence is neutral, never a deduction). Deterministic, presence detection.
Readiness · Performance — Whether asynchronous code stays responsive — it avoids sync-over-async blocking (a .NET .Wait()/.GetAwaiter().GetResult(), a time.sleep or blocking HTTP call inside a Python coroutine, a *Sync call inside an async JavaScript function, block_on inside a Rust async fn, runBlocking inside a Kotlin suspend function, block() inside a Reactor publisher) that stalls a thread or event loop and risks deadlock, and, where the code is a reusable library on .NET, awaits with ConfigureAwait(false) so it never captures and stalls its caller's context.
Method: Production-source scan: sync-over-async blocking counted everywhere — .Wait()/.GetAwaiter().GetResult() in .NET; off .NET, read from each language's code model, a blocking call inside an async function (Python, TS/JS, Rust, Kotlin, Swift, Dart) or inside a Java method returning a Reactor Mono/Flux or a Scala method returning a Future or effect — and, for a .NET library with ≥5 awaits, the share of awaits using ConfigureAwait(false). Deterministic, syntax/text detection.
Other · Code Health — Whether the code avoids sync-over-async (deadlock-prone blocking on tasks) and async void.
Method: Roslyn syntax scan: async methods scanned for .Wait()/.GetAwaiter().GetResult() and async-void outside event handlers. Deterministic, hard fact per invocation.
The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception. (×2) — libs/partners/openai/langchain_openai/chat_models/_client_utils.py:383, libs/partners/anthropic/langchain_anthropic/_client_utils.py:41
What to do
Task from `asyncio.get_running_loop().create_task` is not kept
Other · Code Health — Whether any branch is dead by construction — a switch arm whose label can never equal a case-normalised subject, or an `else if` whose predicate the arm above has already swallowed.
Method: Roslyn syntax + semantics: switch labels compared against the subject's own case normaliser, and if/else-if chains checked for a literal an earlier arm's containment test already swallows. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X13 · Undrained process stream10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a child process that has BOTH standard streams redirected drains both — reading one to the end while the other is never read deadlocks once the child fills the unread pipe.
Method: Roslyn syntax + semantics: ProcessStartInfo launches with both streams redirected, checked for a drain of each stream across the enclosing type. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `spawn` imported from `child_process` whose stdout and stderr are both pipes (no options, no `stdio`, or `stdio` of `'pipe'`), bound to a local that never leaves its scope, where exactly one of the two streams is read, the other never, and the child’s `close`/`exit` (or the read stream’s end) is awaited; a shell redirect in the call’s arguments or a `kill` of the child suppresses it. The same rule reads Python’s `subprocess.Popen`, Dart’s `Process.start`, Ruby’s `Open3.popen3`, and Scala’s JDK process starts (`new ProcessBuilder(…).start()` with no `redirectErrorStream`/`redirectError`/`redirectOutput`/`inheritIO`, `Runtime.getRuntime.exec`) where one of `getInputStream`/`getErrorStream` is read and the other never while `waitFor()` is called or the read stream is read to its end. Deterministic, provable per finding. Advisory.
Other · Security — Whether a hand-rolled public/private IP check can be walked past — a method that unwraps IPv4-mapped IPv6 but returns the opposite verdict for the same host written as IPv4-compatible, 6to4 or NAT64.
Method: Roslyn syntax + semantics: methods that unwrap IPv4-mapped IPv6 and hand-roll IPv4 range carve-outs, checked for whether the IPv6 branch also accounts for the IPv4-compatible, 6to4 and NAT64 embeddings. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X17 · Uncapped recursion over a caller-supplied document2.7 / 10Weak✓ Tool-verified
Other · Security — Whether a walk that recurses through a JSON/XML tree handed in by its caller bounds how deep it will go — an uncapped walk lets the document's nesting choose the stack depth, and the resulting StackOverflowException cannot be caught.
Method: Roslyn syntax + semantics: methods that take a JSON/XML document node and call themselves with a child of it, reachable from an externally-callable member of the same type that accepts a document, checked for any depth parameter, descent counter or threaded arithmetic anywhere in the walk. On a repository with no .NET source it reads TypeScript off the engine’s own token stream (test, vendored, generated and minified paths and `.d.ts` not) with the same rule: a function or method with a parameter typed as a document value — `unknown`, `any`, `object`, `Record<string, unknown|any>`, a JSON alias (`JsonValue`, `JSONObject`, …) or a DOM node global the file does not rebind — that calls itself (bare, or through `this` for a method, or hands itself to a call over the value as in `value.map(walk)`) with something it took out of that value and never through an ancestor accessor such as `closest()` or `parentElement`, that is exported or reached from an exported function (a public method of the same exported class) taking such a value, and that names no depth, level, nesting, recursion, remaining or budget anywhere and threads no `+`/`-` arithmetic through a self-call. Plain JavaScript is not read: with no annotation nothing tells a parsed document from a tree the code built itself. Deterministic, provable per finding. Advisory.
`split_json` is public, takes a document from its caller (line 116) and hands it to `_list_to_dict_preprocessing`, which calls itself at line 75 (`self._list_to_dict_preprocessing`) with a piece of `data` (and at line 79) — and nowhere in `_list_to_dict_preprocessing` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_list_to_dict_preprocessing` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/text-splitters/langchain_text_splitters/json.py:75
`replace` is public and takes `value: JsonValue` from its caller, and it calls itself at line 43 (`self.replace`) with a piece of `value` (and at line 45) — and nowhere in `replace` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `replace` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/partners/typesafe/langchain_typesafe/_assets.py:43
`merge_dicts` is public and takes `left: dict[str, Any]` from its caller, and it calls itself at line 66 (`merge_dicts`) with a piece of `left` — and nowhere in `merge_dicts` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `merge_dicts` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/core/langchain_core/utils/_merge.py:66
`dereference_refs` is public, takes a document from its caller (line 188) and hands it to `_dereference_refs_helper`, which calls itself at line 136 (`_dereference_refs_helper`) with a piece of `obj` (and at line 178) — and nowhere in `_dereference_refs_helper` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_dereference_refs_helper` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/core/langchain_core/utils/json_schema.py:136
`stringify_value` is public and takes `val: Any` from its caller, and it calls itself at line 21 (`stringify_value`) with a piece of `val` — and nowhere in `stringify_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `stringify_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/core/langchain_core/utils/strings.py:21
`add_subgraph` is public and takes `viz: Any` from its caller, and it calls itself at line 190 (`self.add_subgraph`) with a piece of `viz` — and nowhere in `add_subgraph` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `add_subgraph` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — libs/core/langchain_core/runnables/graph_png.py:190
What to do
Each finding names the externally-callable member that accepts the document and the self-call that descends, and states that no depth parameter or counter exists anywhere in the walk. Confirm from the two, then thread a depth argument through the walk and reject documents past a fixed maximum, or rewrite it with an explicit stack.
Other · Code Health — Whether the work a diagnostic log line costs is paid only when that line is wanted — C# evaluates a call's arguments BEFORE the call, so a trace/debug message joined or projected out of a collection is built in full on every pass, and then discarded by a sink the shipped configuration leaves switched off.
Method: Roslyn syntax: log calls at a diagnostic level (a `Log`-prefixed method naming Trace/Debug/Verbose, or a bare `Debug`/`Trace`/`Verbose` on a receiver named for a logger), whose argument list is read for a call whose cost scales with a sequence — a LINQ operator, a materialisation, `string.Join`, a serializer — with no enclosing level check or conditional-compilation region. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `debug`/`trace`/`verbose` call on a receiver named for a logger, or a `log`-prefixed method naming the level, whose argument calls an array operator (`map`/`filter`/`reduce`/`sort`/…), `Array.from`, `Object.keys/values/entries`, `JSON.stringify`/`util.inspect` over anything but a literal, or an array `join` — outside any arrow or function passed as an argument, which the logger calls only when the level is on — with no enclosing `if`, `&&` or `?:` whose condition names a level, a level string, or the `NODE_ENV`/`__DEV__`/`DEV` build switch. Deterministic, provable per finding. Advisory.
`debug` at line 161 is called with an argument built by `sorted(overrides)` (line 163), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — libs/langchain_v1/langchain/agents/middleware/model_fallback.py:161
What to do
In Python, put the construction behind the logger's own check (`if logger.isEnabledFor(logging.DEBUG):`), or pass the collection itself with a `%s` placeholder (`logger.debug("Items %s", items)`) so the logging module renders it only when the record is emitted. The placeholder alone is not the fix when the argument is still built first: it defers the formatting, not a `json.dumps`, a `join` or a comprehension in the argument, and an f-string defers nothing at all.
Do you agree with this assessment?
X24 · Document value interpolated into markup unescaped10.0 / 10Exemplary○ Nothing flagged
Other · Security — Whether text read out of the document being converted is escaped before it is written into generated markup — a value the document's author chose, interpolated into an attribute the surrounding literal delimits, can close that attribute and open another.
Method: Roslyn semantic model over the whole compilation: a string-typed `Value`/`InnerText`/`InnerXml`/`Text` member declared inside `DocumentFormat.OpenXml` or `System.Xml` is a taint SOURCE, propagated through assignments, returns, arguments, tuple elements and string composition to its transitive closure, then read at interpolated-string holes that sit in a markup position the surrounding literal itself delimits. Escaper/encoder calls and enclosing validator conditions cut the flow. Flow- and container-insensitive by construction. A second arm needs no provenance at all and reports a type that CONTRADICTS ITSELF — the same expression escaped at one delimited markup hole and interpolated raw at another hole in the same markup position of the same type, which the type's own escaping proves is a defect without knowing where the value came from. On a repository with no .NET source it reads JavaScript/TypeScript off the token stream with the same rule: a DOM read of raw document text (`getAttribute`, `textContent`, `innerText`, `nodeValue`) is the source, propagated through local bindings and string composition, and judged at template-literal and concatenation holes in the same two delimited markup positions; escapers and validating conditions cut it, and documentation-site, test, vendored and minified scripts are not read. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether a value the caller is invited to supply is the value the type actually uses — a constructor parameter stored in a private field that nothing ever reads while the default it was given is spelled out a second time at the site that should have read it, a keyed lookup that falls back to a different setting than the one its key names while the same type falls back to the matching one for that same key, or a culture-sensitive parse given no format provider by a type that feeds its own settable culture to the same kind of parse elsewhere, or a number an entry point writes to standard output under the host's culture while the same entry point formats with the invariant culture elsewhere. Either way, every caller who supplies a value silently gets something else.
Method: Roslyn syntax: private instance fields of a non-partial type assigned in a constructor from one of its own parameters with a `??` fallback, checked for whether anything in the type body reads the field and whether that same fallback expression is spelled out again outside the constructor; and `??` fallbacks onto a member access from a lookup call carrying exactly one string literal, grouped by that key across the type and checked for a fallback member whose folded name disagrees with the key while a sibling site for the same key agrees with it. On a repository with no .NET source the first two arms read JavaScript/TypeScript off the engine’s own token stream (tests included, bundles and vendored paths not): a `#x`, `private` or `private` parameter-property instance field filled in the constructor from a parameter (or one member of one) through `??`/`||` or a parameter default, never read anywhere in the file by name, whose constructed default is spelled again in the class body; and `lookup("key") ?? s.member` grouped by key per class, or per module outside every class. The culture arm has no JavaScript counterpart: its parses take no locale. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X27 · Collection changed while being enumerated10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a `for` loop leaves the `dict`, `set` or `deque` it is walking alone — CPython's iterators over those check that the collection has not changed size since the loop began, so a body that removes from (or empties) the very collection the loop is walking makes the next step raise `RuntimeError: dictionary changed size during iteration` and the remaining items are never seen.
Method: Roslyn syntax + semantics: `foreach` statements whose body calls a structural mutator (`Add`/`Remove`/`Clear`/`Insert`/…) on the very expression the loop is enumerating. Two arms. ARM A — the source is a concrete fragile BCL collection, or a live `Keys`/`Values` view over one, and the mutator resolves to that same collection's own member; concurrent and immutable collections and arrays are outside the population by construction, since their enumerators survive a structural change. ARM B — the source is an argument-less accessor CALL on a receiver whose body is in source: the accessor must return a stored field VERBATIM and a sibling member must structurally change that same field, both read off the implementations rather than from the members' names. A mutation the loop provably exits immediately after (`break`/`return`/`throw`/`goto`), or one written inside a nested loop or a lambda, is counted and never reported. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X28 · Index access outside its own emptiness guard6.2 / 10Adequate✓ Tool-verified
Other · Code Health — Whether a condition that tests a value for emptiness indexes that same value only where the test holds — an `||` written one parenthesis too far to the left leaves an index access outside the guard beside it, so the empty case the guard exists to anticipate reaches the index and throws.
Method: Roslyn syntax only, no semantic model: the OUTERMOST `&&`/`||` of every boolean condition, read for a symbol the condition tests for emptiness (`string.IsNullOrEmpty`/`IsNullOrWhiteSpace`, a `Length`/`Count` comparison against a literal, `Any()`, a `Length`/`Count` pattern, or a comparison against `""`) and ALSO indexes. Each `symbol[...]` access is placed by a boolean-reachability walk from the access up to the outermost connective: an access is COVERED when some enclosing step has it in the right operand and the left operand, under the truth value that step forces, proves the symbol non-empty — a recursion over `&&`/`||` whose true- and false-directions are asymmetric. A finding needs BOTH an uncovered access and a covered one on the same symbol in the same condition, which is the agreeing twin that separates a misplaced parenthesis from an unrelated length test. Bare index accesses with no emptiness test in the condition are neither counted nor reported; a non-identifier receiver and a lambda nested inside the condition are outside the population. Deterministic, provable per finding. Advisory.
This condition tests `others` for emptiness and then indexes it on a branch that test does not reach. `others[0]` is evaluated whenever the guarded half is false — which includes the case the guard exists to anticipate, `others` being empty — so an empty `others` indexes position 0 of nothing and throws. This same condition already shows the intended bracketing at line 202: `others[0]` sits INSIDE the guard. Either the guard is load-bearing, in which case this access escapes it and crashes, or `others` cannot be empty here, in which case the guard beside it is dead code — the condition is wrong under both readings. Move the parenthesis so the emptiness test brackets every access to `others`. — libs/core/langchain_core/prompts/structured.py:203
What to do
Each finding names the index access that escapes the guard and the line of the correctly bracketed access beside it. Compare the two: they differ only in where one parenthesis sits. Move it so the emptiness test brackets every access to that symbol — and if the value provably cannot be empty at this point, delete the test rather than leave a condition that guards one access and not its neighbour.
Other · Code Health — Whether exceptions are handled rather than silently swallowed or rethrown with lost stack traces.
Method: Roslyn syntax scan: every catch clause counted; empty catches and bare rethrows flagged. Population is all catch clauses, not estimated. Deterministic, hard fact.
`except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter. (×14) — libs/partners/openai/langchain_openai/chat_models/_client_utils.py:229, libs/partners/openai/langchain_openai/chat_models/_client_utils.py:319, libs/langchain_v1/langchain/agents/middleware/summarization.py:1039, …
An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch. (×4) — libs/partners/openai/langchain_openai/chat_models/_client_utils.py:371, libs/partners/openai/langchain_openai/chat_models/_client_utils.py:384, libs/partners/anthropic/langchain_anthropic/_client_utils.py:29, …
What to do
Swallowed exception (caught, then discarded)
Do you agree with this assessment?
X30 · Support guard that admits what it rejects10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a guard written as a NEGATED `||` says what its author meant — `!(a || b || x != k)` is `!a && !b && x == k` by De Morgan, so a bail-out that mixes capabilities the code needs with a fault it refuses turns inside out: it fires only where the capabilities are ABSENT, and lets every value the fault term names walk straight into the body that cannot handle it.
Method: Roslyn syntax only, no semantic model: every logical-not whose operand is a parenthesised `||` chain of two or more disjuncts, flattened (a left-nested `a || b || c` read once would see `(a || b)` as one disjunct). A site enters the population on that shape alone. A finding additionally needs the disjuncts to DISAGREE in polarity: at least one bare boolean read — an identifier or member access, never an invocation, which is a predicate rather than a capability flag — and at least one `x != <constant>`, the only form that negates into an exact-value pin (`== null` negates into a looser requirement and is outside the fault set). Consistently-polarised disjunctions, all-fault or all-capability, are counted and never reported; a negated `&&` is outside the population entirely. No same-receiver gate: it was measured to cost a real defect and remove no false positive. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether log calls use message templates (queryable) rather than interpolated strings.
Method: Roslyn syntax scan: every log call-site counted; interpolated-string first-argument violations flagged. Population is all log calls, not estimated. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `trace`/`debug`/`info`/`warn`/`error`/`fatal`/`verbose`/`silly`/`http`/`log` call on a receiver named for a logger, in a package whose own or an enclosing `package.json` declares a logger that carries values as fields (pino, pino-http, nestjs-pino, Fastify, winston, bunyan, tslog, LogTape, roarr), whose first deciding argument is a template literal with substitutions; an object-literal fields argument is stepped over, a plain string message clears the call. Python is read the same way: a `debug`/`info`/`warning`/`error`/`exception`/`critical`/`log` call on a logger in a file that imports the standard library’s `logging` or structlog (loguru, which formats at the call, is not judged), whose message is a whole f-string with a non-constant field; a `%`-formatted, `.format()`-ed or concatenated message is not convicted, as in C#. PHP is read the same way: a PSR-3 level call (`emergency`…`debug`, `log`) on a logger (`$logger`, `$this->logger`, Laravel’s `Log::`, `logger()`, `\Drupal::logger()`) in a package whose `composer.json` requires a PSR-3 logger or a framework that hands one out (psr/log, Monolog, Laravel, Symfony, Drupal, CakePHP), or a file that imports one, whose message is a double-quoted string interpolating a variable; a single-quoted message clears the call, and `sprintf` or `.` concatenation is not convicted, as in C#. Dart is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on Sentry’s structured logger (`Sentry.logger`) whose message is a whole string literal interpolating a value (`$name`, `${…}`); the `Sentry.logger.fmt` template API clears the call. Dart that logs only through loggers with one message and no fields (package:logging, package:logger, talker, dart:developer) is not applicable rather than a reach gap. Ruby is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on the console gem’s `Console` (declared by a Gemfile, gemspec or Gemfile.lock, or required) or, where SemanticLogger, Ougai or dry-logger is declared or required, on a receiver named for a logger (`logger`, `@logger`, `Rails.logger`, `log`), whose first deciding argument is, as the whole argument, a double-quoted string interpolating a non-constant value (`#{…}`, `#@ivar`); a plain literal clears the call, keyword arguments are the fields, and a block, `%`-format or `+` concatenation is not convicted. Ruby that logs only through the standard Logger (Rails.logger) is not applicable rather than a reach gap. Deterministic.
`warning` at line 309 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:309
`warning` at line 231 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py:231
The score is the rank-weighted fold of these lenses (worst-heaviest), each including its meta-dimensions; a lens with a Critical contributor is capped at Fair (its band reads "gated by …") and is never the strongest area however high its average.
Unscored — 4 check(s) recorded observations but carry no score
These checks ran and found something, but they do not carry a score — either by design (an advisory check reports evidence rather than grading it) or because they could not be scored here. They are excluded from the score for that reason, not because there was nothing to see.
D11 Test Reliability — 4 observation(s) recorded · This repository declares 4 of its own test(s) unreliable. The built-in reliability runner does not support this repository's ecosystem (.py), so the suite was not re-run and no reliability score is given — these are the repository's own declarations, not our measurement.
X10 Duplicated predicate — 40 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X6 Hand-rolled structured-format parsing — 1 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X7 Silent fallback defaults — 5 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
Not evidenced — 1 control(s) we could not find positive evidence for
These checks grade a working control, and the repository shows no evidence of one. That is deliberately not scored as a zero: a repository cannot show an ops runbook, a database TTL or an infrastructure-side audit log, so absence of evidence here is not evidence the control is missing. It is also not a statement that the check is irrelevant to this codebase — the thing it grades applies; we just could not see it. Excluded from the score either way.
P5 DR & Backup — not evidenced — repo shows no backup/RTO/RPO controls; absence of evidence is not evidence of a working control
Not included — 60 check(s) not relevant to this codebase
These checks had nothing to measure here (no tests, no git history, the codebase is small, or the architecture style doesn't apply), so they're omitted above rather than scored low.
AC1 Text alternatives — No web markup found — accessibility is not applicable to this repository.
AC2 Forms & labels — No web markup found — accessibility is not applicable to this repository.
AC3 Page structure — No web markup found — accessibility is not applicable to this repository.
AC4 Keyboard semantics — No web markup found — accessibility is not applicable to this repository.
AC5 ARIA correctness — No web markup found — accessibility is not applicable to this repository.
AC6 Visual & motion safety — No web markup found — accessibility is not applicable to this repository.
AX1 Captive dependencies — Not applicable: this repository's Python imports no dependency-injection container and defines no container of its own — nothing that both registers and resolves bindings, and nothing that names two lifetimes — so nothing holds one lifetime's instance while handing out another's.
AX2 Stateful singletons — No container singleton was found, so there is no shared instance for concurrent requests to race on. No function in this Python code is served by a threaded web framework (a Flask, Bottle or FastAPI route, a Django or Pyramid view), so no module is shared between request threads. TypeScript/JavaScript runs each process's requests on one event loop, so no two requests write a shared object at the same instant (interleaving across an await is a different defect).
AX5 Architecture & structure — not assessed — architecture style/structure is computed from a project graph (projects, types, module namespaces) that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX6 Interface segregation — not assessed — interface segregation is computed over a type surface that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX7 Slice cohesion — not applicable — not a vertical-slice architecture
AX8 Test isolation — no test/production split to check
AX9 CQS / query purity — no CQRS query handlers detected — query purity is not applicable to this codebase
AXB2 Runtime readiness — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
AXR1 Runtime accessibility — compose up failed (exit 17 — an image could not be built) — failed to solve: process "/bin/sh -c uv sync --dev" did not complete successfully: exit code: 1; runtime evidence skipped This is a statement about this run, not a statement about your application: nothing here says the surface is inaccessible, only that it was never rendered.
C1 Data Protection — Not assessed: these personal data controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks personal data controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C2 Access Controls — No access-control surface detected in the analyzed source — this repository registers no route and starts no server another machine can reach (no Flask/FastAPI/Starlette route, Django urlpatterns or class-based view, Tornado handler). Access control is therefore N/A here — a library or command-line tool is authorized by the application that serves it, not by itself. If this codebase grows request handlers, the dimension reactivates and a default-deny posture is expected then.
C3 Audit Trail — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential in a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or MongoEngine model, a migration or a SQL schema — and no database or data-store client (Django ORM, SQLAlchemy, psycopg, PyMongo, …) in the source either, so this repository keeps no sensitive data whose changes an audit trail would record. If it does (through a store configured outside this repository, for instance), the trail belongs to wherever that data is stored.
C4 Data Retention — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential on a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or mongoengine model, in a migration or in a SQL schema — and no database or data-store client (django.db, sqlalchemy, psycopg2, pymongo, sqlite3, …) imported either, so this repository keeps no personal data whose lifetime a retention limit would bound.
C5 Data-Subject Rights — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential on a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or mongoengine model, in a migration or in a SQL schema — and no database or data-store client (django.db, sqlalchemy, psycopg2, pymongo, sqlite3, …) imported either, so this repository keeps no personal data for a data subject to erase, export or consent over.
D10 Test Quality — ~160484 lines of test source are present (.py) but no test cases reached the test census for this repository — no test root we could resolve declared them, or the files we read declare no cases in a test framework we recognise — so skipped/assertion-free tests couldn't be counted. Not scored — this is a gap in the analyzer, not a finding about this repository.
D12 Dependency Hygiene — Not scored — 36 shipped Python distribution(s) were read, but the outdated signal needs pypi.org, and no declaration here carries an exact pin to ask about — a floor or a range installs the newest release it admits and cannot be behind one, so this dimension's own question is only partly answered. NOT a finding that these dependencies are current or healthy.
D18 Solution Shape — D18 scores the shape of a .NET solution; this repository has no .NET solution or project files, so the dimension does not apply.
D21 Naming Consistency — D21 withholds its sibling role token rows: 1 candidate(s) found and not reported.
D22 Internal API Consistency — API consistency is measured on C# only; the exposed Python surface was not measured.
D23 Boundary Type-Coupling — No bounded-context organisation was detected either — neither a context-shaped layout, nor 2+ sibling source directories each declaring an aggregate root, nor 2+ sibling projects each declaring an entity of their own or taking another project's integration events. Declaring this codebase's bounded contexts (≥2) would let cross-boundary type coupling be assessed. Declare them in `.codehealth/config.yaml` at the repository root (create it if absent), mapping each context name to the module-path or namespace prefixes that belong to it — e.g. `architecture:` → `contexts:` → `Billing: ["src/billing", "Acme.Billing"]`, `Catalog: ["src/catalog", "Acme.Catalog"]`.
D24 Comment Value — D24 reads C#, Visual Basic, TypeScript and JavaScript comments only; comments in this repository's .py source were not judged.
D25 ADR Conformance — no ADRs to check
D32 Data Compliance (PII/GDPR) — No personal data was found crossing a boundary the PII/GDPR ruleset checks — nothing written to a log or console sink, placed in a URL or query string, or persisted to browser storage. That is a clean result for the LEAK surface only: this ruleset detects personal data escaping, it does not inventory the personal data a repository holds, so it is not evidence that this repository has no personal-data surface. The personal-data map (Appendix C) and the C1-C5 compliance cards are what speak to that.
D37 Vulnerability-disclosure Policy — No vulnerability-disclosure policy file found (SECURITY.md/.markdown/.rst/.txt at root or under .github/.forgejo/.gitea/docs, .well-known/security.txt). A coordinated-disclosure policy may live off-repo, so this is not evidenced rather than failed.
D40 Network Egress Confinement — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
D41 Kernel & Syscall Confinement — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
D42 Runtime Threat Enforcement — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
D7 Architectural Integrity — no checkable ADRs, and no project-reference graph for the cycle pass to read — so this dimension makes no claim about dependency cycles in either direction (where this repository's language has an import-cycle lens, cycles are reported there). Architectural integrity not assessed
D8 Code Coverage — Coverage not included — suite not readable by the collector
DM1 Domain Modelling — not scored — this repository shows only 1 of the 3 signals this lens looks for (96 value object(s))
ED1 Event-Driven — not scored — this repository shows none of the 3 signals this lens looks for
ED5 Idempotency — no mutating command handlers or message consumers detected — idempotency check not applicable
ES1 Event Sourcing — not scored — this repository shows none of the 3 signals this lens looks for
GD1 Unfinished & placeholder code — no source files were read — this check reads C#, F#, JavaScript/TypeScript, Dart, Ruby and Scala, and none was read for this repository's product. That is a limit of the analyzer, not a finding about your code.
IC1 Incompleteness & stubs — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
M4 Documentation accuracy — Not applicable: the 26 current-state document(s) make no claim of a kind M4 checks. 4 claim(s) of kinds M4 does not check were not checked (path 3, environment variable 1); M4 checks only links and versions and artefact counts.
P12 CI test-gate honesty — Reported, not scored — and nothing was matched here. The coverage check applies to any stack, and the automatic-re-run check to any GitHub-Actions workflow, but the checks for excluded tests, skipped tests and sleep-based synchronisation currently recognise only some ecosystems' test-runner idioms, so on a repository built with another stack the zeros below mean 'not checked', not 'clean'.
P7 Outbound HTTP resilience — not applicable — no HTTP server, API framework or worker entry point was found in the Python source, so there is no service whose uptime a failing dependency could take down
P9 Domain vs controller coverage — coverage not measured: this check compares the coverage of the analyzer's own test run across the domain and web layers, and that run measured none here — Test coverage (D8) says why
PF2 Allocation hygiene — Not scored: this check counted allocation-aware idioms (Span, pools, stackalloc) per line, which describes what kind of code a repository is rather than whether it has an allocation problem, so it was withdrawn. Nothing here is a finding about your code.
S1 Web-Security Posture — Not assessed: these web-security controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks web-security controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
X15 Unvalidated length from an untrusted reader — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X16 Unfloored truncation loop — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X18 Disposal-pattern correctness — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X19 Unrestored process-global state — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X2 Cancellation propagation — no C# was loaded; this repository's Python was read, and no request in it can be cancelled by a caller — a Python request takes no token: asyncio cancels the task and trio or anyio the scope that made it, from outside the call, and requests, httpx, aiohttp and gRPC take a timeout, not a cancellation
X20 Mistyped argument guard — This check asks whether an argument guard reports an EMPTY value as a NULL one, which needs a language that throws a null-specific argument exception — .NET's ArgumentNullException, the JVM's NullPointerException, Dart's ArgumentError.notNull. This repository contains none of those languages: the ones it is written in have a single exception for a bad argument, so there is no pair of exceptions to confuse and nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
X21 Side-effecting pattern guard — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X22 Contradicted release guard — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X26 Unsynchronised callback handoff — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X29 Per-element action decided by a fixed element — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X32 Type resolved by simple name across every loaded assembly — This check is about how a .NET program searches the assemblies loaded into its process for a type, and this repository contains no .NET source, so there is nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
X5 Nullable reference types — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X9 Subsumed condition operand — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
Appendix A — Findings (grouped)
The findings behind the scores, grouped by severity, then by dimension and kind. The high-severity issues are enumerated in full below; items per group are capped at 25 with any overflow stated explicitly per group, never silently truncated. The complete machine-readable list of every finding (all severities) is the companion findings.md in this report's bundle.
D11 · Test Reliability· Test declared unreliable · ×4
Test declared unreliable: test_tool_calling libs/partners/groq/tests/integration_tests/test_standard.py:37— This test is disabled or skipped with a reason naming unreliability — the repository's own words: "Retry flaky tool calling behavior". A test that is skipped for flakiness is neither passing nor protecting the code it covers; either stabilise it or delete it, but do not leave it disabled indefinitely. (Found by reading the repository's own test source — the suite itself was not re-run, since the reliability runner does not support this ecosystem.)
Test declared unreliable: test_tool_choice libs/partners/groq/tests/integration_tests/test_standard.py:42— This test is disabled or skipped with a reason naming unreliability — the repository's own words: "Retry flaky tool choice behavior". A test that is skipped for flakiness is neither passing nor protecting the code it covers; either stabilise it or delete it, but do not leave it disabled indefinitely. (Found by reading the repository's own test source — the suite itself was not re-run, since the reliability runner does not support this ecosystem.)
Test declared unreliable: test_tool_calling_async libs/partners/groq/tests/integration_tests/test_standard.py:47— This test is disabled or skipped with a reason naming unreliability — the repository's own words: "Retry flaky tool calling behavior". A test that is skipped for flakiness is neither passing nor protecting the code it covers; either stabilise it or delete it, but do not leave it disabled indefinitely. (Found by reading the repository's own test source — the suite itself was not re-run, since the reliability runner does not support this ecosystem.)
Test declared unreliable: test_tool_calling_with_no_arguments libs/partners/groq/tests/integration_tests/test_standard.py:52— This test is disabled or skipped with a reason naming unreliability — the repository's own words: "Retry flaky tool calling behavior". A test that is skipped for flakiness is neither passing nor protecting the code it covers; either stabilise it or delete it, but do not leave it disabled indefinitely. (Found by reading the repository's own test source — the suite itself was not re-run, since the reliability runner does not support this ecosystem.)
Orphaned knowledge libs/langchain/langchain_classic/chains/constitutional_ai/principles.py:1— No living knowledge remains for this large file — its last meaningful change has decayed away; if it breaks, no one currently understands it. Schedule a read-through / add characterisation tests before it bites.
TodoComment libs/partners/perplexity/tests/integration_tests/test_chat_models_standard.py:37— # TODO, API regressed for some reason after 2025-04-15 — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/llms/azure.py:61— # TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/embeddings/azure.py:116— # TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/chat_models/azure.py:514— # TODO: Remove OPENAI_API_KEY support to avoid possible conflict when using — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/llms/base.py:468— # TODO: write a unit test for this — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/embeddings/base.py:197— # TODO: Move to AzureOpenAIEmbeddings. — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/chat_models/_client_utils.py:382— # TODO(someday): support non asyncio runtimes here — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/anthropic/langchain_anthropic/_client_utils.py:40— # TODO(someday): support non asyncio runtimes here — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/openai/langchain_openai/chat_models/base.py:2432— # TODO: Count bound tools as part of input. — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/ollama/tests/integration_tests/chat_models/test_chat_models_standard.py:27— # TODO: update after Ollama implements — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/ollama/langchain_ollama/_compat.py:46— # TODO: AudioContentBlock once models support — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/ollama/langchain_ollama/_compat.py:48— # TODO: FileContentBlock once models support — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/mistralai/langchain_mistralai/chat_models.py:803— # TODO: handle retries — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/mistralai/langchain_mistralai/embeddings.py:181— # TODO: handle retries — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/mistralai/langchain_mistralai/chat_models.py:821— # TODO: handle retries and max_concurrency — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/mistralai/langchain_mistralai/embeddings.py:192— # TODO: handle retries and max_concurrency — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/mistralai/langchain_mistralai/chat_models.py:1279— # TODO: Update to pass in tool name as tool_choice if/when Mistral supports — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/exa/langchain_exa/tools.py:122— # TODO: rename `type` to something else, as it is a reserved keyword — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/chroma/tests/integration_tests/test_vectorstores.py:536— # TODO: RELEVANCE SCORE IS BROKEN. FIX TEST — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/chroma/langchain_chroma/vectorstores.py:41— # TODO: Chroma can do batch querying, — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/anthropic/tests/integration_tests/test_chat_models.py:2303— # TODO: update example to trigger action — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/anthropic/langchain_anthropic/chat_models.py:2574— # TODO: dump all `data` with `mode="json"` — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/partners/anthropic/langchain_anthropic/chat_models.py:2992— # TODO: make `method="json_schema"` the default in a future release. — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_middleware_type_errors.py:180— # TODO: TYPE ERROR not yet detected by mypy - AnalysisMiddleware expects AnalysisResult, — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment libs/langchain_v1/langchain/chat_models/base.py:52— # TODO: replace with operator.call when lower bounding to Python 3.11 — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
FileTooLong: runnables/base.py libs/core/langchain_core/runnables/base.py— FileTooLong — 3556 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3056 over it, 7.11× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: chat_models/base.py libs/partners/openai/langchain_openai/chat_models/base.py— FileTooLong — 3538 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3038 over it, 7.08× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_anthropic/chat_models.py libs/partners/anthropic/langchain_anthropic/chat_models.py— FileTooLong — 1867 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1367 over it, 3.73× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: language_models/chat_models.py libs/core/langchain_core/language_models/chat_models.py— FileTooLong — 1755 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1255 over it, 3.51× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: callbacks/manager.py libs/core/langchain_core/callbacks/manager.py— FileTooLong — 1582 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1082 over it, 3.16× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: agents/factory.py libs/langchain_v1/langchain/agents/factory.py— FileTooLong — 1269 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 769 over it, 2.54× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_qdrant/vectorstores.py libs/partners/qdrant/langchain_qdrant/vectorstores.py— FileTooLong — 1254 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 754 over it, 2.51× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 1169 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 669 over it, 2.34× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: evaluation/runner_utils.py libs/langchain/langchain_classic/smith/evaluation/runner_utils.py— FileTooLong — 1155 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 655 over it, 2.31× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_ollama/chat_models.py libs/partners/ollama/langchain_ollama/chat_models.py— FileTooLong — 1042 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 542 over it, 2.08× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: agents/agent.py libs/langchain/langchain_classic/agents/agent.py— FileTooLong — 1038 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 538 over it, 2.08× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_perplexity/chat_models.py libs/partners/perplexity/langchain_perplexity/chat_models.py— FileTooLong — 1038 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 538 over it, 2.08× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: language_models/llms.py libs/core/langchain_core/language_models/llms.py— FileTooLong — 1033 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 533 over it, 2.07× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: tools/base.py libs/core/langchain_core/tools/base.py— FileTooLong — 984 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 484 over it, 1.97× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_openrouter/chat_models.py libs/partners/openrouter/langchain_openrouter/chat_models.py— FileTooLong — 953 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 453 over it, 1.91× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: chat_models/huggingface.py libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py— FileTooLong — 894 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 394 over it, 1.79× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_mistralai/chat_models.py libs/partners/mistralai/langchain_mistralai/chat_models.py— FileTooLong — 890 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 390 over it, 1.78× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: language_models/chat_model_stream.py libs/core/langchain_core/language_models/chat_model_stream.py— FileTooLong — 882 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 382 over it, 1.76× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 877 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 377 over it, 1.75× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_groq/chat_models.py libs/partners/groq/langchain_groq/chat_models.py— FileTooLong — 835 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 335 over it, 1.67× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: block_translators/openai.py libs/core/langchain_core/messages/block_translators/openai.py— FileTooLong — 803 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 303 over it, 1.61× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: middleware/types.py libs/langchain_v1/langchain/agents/middleware/types.py— FileTooLong — 800 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 300 over it, 1.60× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: chat_models/azure.py libs/partners/openai/langchain_openai/chat_models/azure.py— FileTooLong — 772 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 272 over it, 1.54× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: tracers/event_stream.py libs/core/langchain_core/tracers/event_stream.py— FileTooLong — 763 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 263 over it, 1.53× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: langchain_chroma/vectorstores.py libs/partners/chroma/langchain_chroma/vectorstores.py— FileTooLong — 726 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 226 over it, 1.45× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
Duplicated block (15 lines × 2) libs/core/langchain_core/messages/ai.py:279— libs/core/langchain_core/messages/ai.py:279-293 | libs/core/langchain_core/messages/block_translators/bedrock.py:17-31 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/ai.py:279` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (15 lines × 2) libs/core/langchain_core/output_parsers/base.py:100— libs/core/langchain_core/output_parsers/base.py:100-114 | libs/core/langchain_core/output_parsers/base.py:210-224 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) libs/core/langchain_core/output_parsers/base.py:123— libs/core/langchain_core/output_parsers/base.py:123-137 | libs/core/langchain_core/output_parsers/base.py:233-247 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) libs/core/langchain_core/runnables/base.py:4131— libs/core/langchain_core/runnables/base.py:4131-4145 | libs/core/langchain_core/runnables/base.py:5128-5142 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/runnables/base.py:5144` calls `super`, `get_graph` and `libs/core/langchain_core/runnables/base.py:4147` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15 lines × 2) libs/core/langchain_core/runnables/fallbacks.py:273— libs/core/langchain_core/runnables/fallbacks.py:273-287 | libs/core/langchain_core/runnables/fallbacks.py:369-383 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/fallbacks.py:273` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 2) libs/langchain/langchain_classic/agents/xml/base.py:71— libs/langchain/langchain_classic/agents/xml/base.py:71-85 | libs/langchain/langchain_classic/agents/xml/base.py:96-110 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:195— libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:195-209 | libs/partners/openai/langchain_openai/embeddings/base.py:359-373 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:195` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15 lines × 2) libs/partners/ollama/langchain_ollama/chat_models.py:1212— libs/partners/ollama/langchain_ollama/chat_models.py:1212-1226 | libs/partners/ollama/langchain_ollama/chat_models.py:1400-1414 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/ollama/langchain_ollama/chat_models.py:1212` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (15 lines × 2) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:236— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:236-250 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:350-364 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 2) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:256— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:256-270 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:370-384 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 2) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:275— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:275-289 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:312-326 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:587— libs/partners/qdrant/langchain_qdrant/vectorstores.py:587-601 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:682-696 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:861— libs/partners/qdrant/langchain_qdrant/qdrant.py:861-875 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1151-1165 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on. Note first that the copies are not typed on the same thing: the declarations holding them bind `ids` to `list[str | int] | None = None` in one and `list[str] | None = None` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (15 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1880— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1880-1894 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1903-1917 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/agents/openai_assistant/base.py:595— libs/langchain/langchain_classic/agents/openai_assistant/base.py:595-602 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:752-759 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/chains/base.py:137— libs/langchain/langchain_classic/chains/base.py:137-144 | libs/langchain/langchain_classic/chains/base.py:193-200 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:169— libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:169-176 | libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:226-233 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/memory/summary_buffer.py:116— libs/langchain/langchain_classic/memory/summary_buffer.py:116-123 | libs/langchain/langchain_classic/memory/summary_buffer.py:130-137 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/retrievers/ensemble.py:115— libs/langchain/langchain_classic/retrievers/ensemble.py:115-122 | libs/langchain/langchain_classic/retrievers/ensemble.py:152-159 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/retrievers/ensemble.py:115` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/retrievers/merger_retriever.py:77— libs/langchain/langchain_classic/retrievers/merger_retriever.py:77-84 | libs/langchain/langchain_classic/retrievers/merger_retriever.py:112-119 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8 lines × 2) libs/langchain_v1/langchain/agents/factory.py:351— libs/langchain_v1/langchain/agents/factory.py:351-358 | libs/langchain_v1/langchain/agents/factory.py:442-449 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) libs/partners/anthropic/langchain_anthropic/chat_models.py:1688— libs/partners/anthropic/langchain_anthropic/chat_models.py:1688-1695 | REDACTED:1334-1341 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/anthropic/langchain_anthropic/chat_models.py:1688` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8 lines × 2) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:198— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:198-205 | libs/partners/openai/langchain_openai/chat_models/base.py:234-243 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (8 lines × 2) libs/partners/openrouter/langchain_openrouter/chat_models.py:599— libs/partners/openrouter/langchain_openrouter/chat_models.py:599-606 | libs/partners/openrouter/langchain_openrouter/chat_models.py:689-696 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/chains/combine_documents/reduce.py:89— libs/langchain/langchain_classic/chains/combine_documents/reduce.py:89-96 | libs/langchain/langchain_classic/chains/combine_documents/reduce.py:121-128 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8 lines × 2) libs/langchain/langchain_classic/chains/qa_with_sources/base.py:96— libs/langchain/langchain_classic/chains/qa_with_sources/base.py:96-103 | libs/langchain/langchain_classic/chains/retrieval_qa/base.py:111-118 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8 lines × 2) libs/langchain_v1/examples/mcp/destructive_interrupt.py:64— libs/langchain_v1/examples/mcp/destructive_interrupt.py:64-72 | libs/langchain_v1/examples/mcp/elicitation.py:34-41 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain_v1/examples/mcp/destructive_interrupt.py:64` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1150— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1150-1157 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1180-1187 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Swallowed exception (caught, then discarded) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:229— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:319— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/langchain_v1/langchain/agents/middleware/summarization.py:1039— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/sys_info.py:96— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/sys_info.py:105— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/sys_info.py:129— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/tracers/core.py:147— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/tracers/stdout.py:26— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/runnables/base.py:166— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/load/serializable.py:103— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/load/serializable.py:340— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/language_models/_compat_bridge.py:153— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/language_models/chat_models.py:123— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) libs/core/langchain_core/language_models/chat_models.py:132— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Hotspot: libs/partners/anthropic/langchain_anthropic/chat_models.py libs/partners/anthropic/langchain_anthropic/chat_models.py:716— libs/partners/anthropic/langchain_anthropic/chat_models.py changed 21 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 95 in chat_models._format_messages at line 716. 10 of those changes were fix/bug commits, and the other 11 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/anthropic/langchain_anthropic/chat_models.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/partners/openai/langchain_openai/chat_models/base.py libs/partners/openai/langchain_openai/chat_models/base.py:4938— libs/partners/openai/langchain_openai/chat_models/base.py changed 15 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 54 in base._construct_responses_api_input at line 4938. 7 of those changes were fix/bug commits, and the other 8 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/openai/langchain_openai/chat_models/base.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/langchain_v1/langchain/agents/factory.py libs/langchain_v1/langchain/agents/factory.py:895— libs/langchain_v1/langchain/agents/factory.py changed 6 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 78 in factory.create_agent at line 895. 5 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/langchain_v1/langchain/agents/factory.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/partners/anthropic/langchain_anthropic/_compat.py libs/partners/anthropic/langchain_anthropic/_compat.py:106— libs/partners/anthropic/langchain_anthropic/_compat.py changed 6 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 41 in _compat._convert_from_v1_to_anthropic at line 106. 4 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/anthropic/langchain_anthropic/_compat.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:1385— REDACTED changed 10 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 22 in ChatFireworks._stream at line 1385. 7 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/core/langchain_core/language_models/chat_models.py libs/core/langchain_core/language_models/chat_models.py:1935— libs/core/langchain_core/language_models/chat_models.py changed 6 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 35 in BaseChatModel._generate_with_cache at line 1935. 2 of those changes were fix/bug commits, and the other 4 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/core/langchain_core/language_models/chat_models.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/partners/openai/langchain_openai/chat_models/_compat.py libs/partners/openai/langchain_openai/chat_models/_compat.py:437— libs/partners/openai/langchain_openai/chat_models/_compat.py changed 4 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 43 in _compat._convert_from_v1_to_responses at line 437. 1 of those changes was a fix/bug commit, and the other 3 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/openai/langchain_openai/chat_models/_compat.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/partners/openai/langchain_openai/chat_models/azure.py libs/partners/openai/langchain_openai/chat_models/azure.py:627— libs/partners/openai/langchain_openai/chat_models/azure.py changed 5 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 26 in AzureChatOpenAI.validate_environment at line 627. 1 of those changes was a fix/bug commit, and the other 4 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/openai/langchain_openai/chat_models/azure.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py:113— libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py changed 3 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 37 in HuggingFacePipeline.from_model_id at line 113. 1 of those changes was a fix/bug commit, and the other 2 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:760— libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py changed 6 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 18 in HumanInTheLoopMiddleware.after_model at line 760. 3 of those changes were fix/bug commits, and the other 3 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/core/langchain_core/tools/base.py libs/core/langchain_core/tools/base.py:1138— libs/core/langchain_core/tools/base.py changed 5 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 17 in BaseTool.arun at line 1138. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/core/langchain_core/tools/base.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/core/langchain_core/utils/function_calling.py libs/core/langchain_core/utils/function_calling.py:377— libs/core/langchain_core/utils/function_calling.py changed 2 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 29 in function_calling.convert_to_openai_function at line 377. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/core/langchain_core/utils/function_calling.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: libs/core/langchain_core/language_models/_compat_bridge.py libs/core/langchain_core/language_models/_compat_bridge.py:586— libs/core/langchain_core/language_models/_compat_bridge.py changed 3 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 16 in _compat_bridge.chunks_to_events at line 586. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-16..2026-11-14, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-16 00:43:30 +00:00' --until='2026-11-14 00:43:30 +00:00' --full-history --no-merges -- libs/core/langchain_core/language_models/_compat_bridge.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
D4 · Code Duplication· Edited copy of a member (26 corresponding lines) · ×13
Edited copy of a member (26 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py:115— libs/partners/chroma/langchain_chroma/vectorstores.py:115-152 | libs/partners/qdrant/langchain_qdrant/_utils.py:14-39 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py:80— libs/partners/chroma/langchain_chroma/vectorstores.py:80-106 | libs/partners/qdrant/langchain_qdrant/_utils.py:43-68 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:745— libs/langchain/langchain_classic/chat_models/base.py:745-770 | libs/langchain_v1/langchain/chat_models/base.py:738-764 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/core/langchain_core/runnables/router.py:144— libs/core/langchain_core/runnables/router.py:144-170 | libs/core/langchain_core/runnables/router.py:181-206 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) REDACTED:1498— REDACTED:1498-1528 | libs/partners/groq/langchain_groq/chat_models.py:850-875 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:231— libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:231-256 | libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:265-290 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/core/langchain_core/language_models/llms.py:825— libs/core/langchain_core/language_models/llms.py:825-850 | libs/core/langchain_core/language_models/llms.py:1099-1131 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/core/langchain_core/prompts/few_shot.py:180— libs/core/langchain_core/prompts/few_shot.py:180-205 | libs/core/langchain_core/prompts/few_shot.py:208-233 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/langchain/langchain_classic/embeddings/base.py:90— libs/langchain/langchain_classic/embeddings/base.py:90-116 | libs/langchain_v1/langchain/embeddings/base.py:163-188 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/core/langchain_core/prompts/chat.py:1176— libs/core/langchain_core/prompts/chat.py:1176-1201 | libs/core/langchain_core/prompts/chat.py:1204-1229 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/langchain/langchain_classic/agents/format_scratchpad/openai_functions.py:40— libs/langchain/langchain_classic/agents/format_scratchpad/openai_functions.py:40-65 | libs/langchain/langchain_classic/agents/format_scratchpad/tools.py:22-48 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/partners/fireworks/langchain_fireworks/rerank.py:136— libs/partners/fireworks/langchain_fireworks/rerank.py:136-161 | libs/partners/fireworks/langchain_fireworks/rerank.py:173-200 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1132— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1132-1157 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1160-1187 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (22 corresponding lines) · ×13
Edited copy of a member (22 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py:904— libs/partners/mistralai/langchain_mistralai/chat_models.py:904-925 | libs/partners/mistralai/langchain_mistralai/chat_models.py:934-955 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/core/langchain_core/output_parsers/transform.py:127— libs/core/langchain_core/output_parsers/transform.py:127-148 | libs/core/langchain_core/output_parsers/transform.py:154-175 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/core/langchain_core/language_models/chat_model_stream.py:248— libs/core/langchain_core/language_models/chat_model_stream.py:248-269 | libs/core/langchain_core/language_models/chat_model_stream.py:1304-1325 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/core/langchain_core/runnables/base.py:6095— libs/core/langchain_core/runnables/base.py:6095-6116 | libs/core/langchain_core/runnables/base.py:6147-6169 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/core/langchain_core/language_models/chat_models.py:695— libs/core/langchain_core/language_models/chat_models.py:695-735 | libs/core/langchain_core/language_models/chat_models.py:746-767 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:365— libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:365-386 | libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:395-416 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/langchain/langchain_classic/chains/base.py:522— libs/langchain/langchain_classic/chains/base.py:522-543 | libs/langchain/langchain_classic/chains/base.py:546-567 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py:159— libs/partners/mistralai/langchain_mistralai/chat_models.py:159-191 | libs/partners/openai/langchain_openai/chat_models/base.py:310-331 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/core/langchain_core/vectorstores/base.py:794— libs/core/langchain_core/vectorstores/base.py:794-815 | libs/core/langchain_core/vectorstores/base.py:824-845 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py:267— libs/langchain/langchain_classic/agents/openai_assistant/base.py:267-288 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:399-421 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:524— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:524-545 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1949-1974 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:619— libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:619-640 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:645-681 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:266— libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:266-287 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:290-326 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (14 lines × 2) libs/core/langchain_core/runnables/base.py:1030— libs/core/langchain_core/runnables/base.py:1030-1043 | libs/core/langchain_core/runnables/configurable.py:182-195 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) libs/core/langchain_core/tools/base.py:1075— libs/core/langchain_core/tools/base.py:1075-1089 | libs/core/langchain_core/tools/base.py:1203-1216 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/tools/base.py:1075` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/tools/base.py:1217` calls `_to_args_and_kwargs` and `libs/core/langchain_core/tools/base.py:1090` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (14 lines × 2) libs/langchain/langchain_classic/chains/loading.py:119— libs/langchain/langchain_classic/chains/loading.py:119-132 | libs/langchain/langchain_classic/chains/loading.py:152-165 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) libs/langchain/langchain_classic/memory/summary_buffer.py:54— libs/langchain/langchain_classic/memory/summary_buffer.py:54-67 | libs/langchain/langchain_classic/memory/summary_buffer.py:73-86 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (14 lines × 2) libs/langchain_v1/langchain/agents/middleware/file_search.py:45— libs/langchain_v1/langchain/agents/middleware/file_search.py:45-58 | libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:24-37 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/file_search.py` and `libs/partners/anthropic/langchain_anthropic/middleware/file_search.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 55 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (14 lines × 2) libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:161— libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:161-174 | libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:219-232 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) libs/partners/anthropic/langchain_anthropic/llms.py:267— libs/partners/anthropic/langchain_anthropic/llms.py:267-280 | libs/partners/anthropic/langchain_anthropic/llms.py:304-317 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/anthropic/langchain_anthropic/llms.py:267` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `prompt` to `str` in one and `PromptValue` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (14 lines × 2) REDACTED:1583— REDACTED:1583-1596 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:938-951 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (14 lines × 2) libs/partners/mistralai/langchain_mistralai/chat_models.py:1380— libs/partners/mistralai/langchain_mistralai/chat_models.py:1380-1393 | libs/partners/openai/langchain_openai/chat_models/base.py:4429-4442 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (14 lines × 2) libs/partners/ollama/langchain_ollama/llms.py:394— libs/partners/ollama/langchain_ollama/llms.py:394-407 | libs/partners/ollama/langchain_ollama/llms.py:436-449 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:2153— libs/partners/qdrant/langchain_qdrant/vectorstores.py:2153-2166 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2182-2195 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:1010— libs/langchain/langchain_classic/chat_models/base.py:1010-1023 | libs/langchain_v1/langchain/chat_models/base.py:1001-1014 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (14 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1406— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1406-1419 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1422-1435 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) libs/core/langchain_core/messages/block_translators/anthropic.py:399— libs/core/langchain_core/messages/block_translators/anthropic.py:399-407 | libs/core/langchain_core/messages/block_translators/anthropic.py:450-458 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) libs/core/langchain_core/runnables/base.py:2345— libs/core/langchain_core/runnables/base.py:2345-2353 | libs/core/langchain_core/runnables/base.py:2395-2403 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:2345` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/agents/openai_assistant/base.py:605— libs/langchain/langchain_classic/agents/openai_assistant/base.py:605-613 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:762-770 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/openai_assistant/base.py:605` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:238— libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:238-246 | libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:272-280 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:238` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/chains/combine_documents/reduce.py:338— libs/langchain/langchain_classic/chains/combine_documents/reduce.py:338-346 | libs/langchain/langchain_classic/chains/combine_documents/reduce.py:377-385 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/combine_documents/reduce.py:338` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:153— libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:153-161 | libs/langchain/langchain_classic/chains/summarize/chain.py:183-191 — before extracting anything, compare `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py` and `libs/langchain/langchain_classic/chains/summarize/chain.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 46 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:153` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:371— libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:371-379 | libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:585-593 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) libs/partners/fireworks/langchain_fireworks/_compat.py:9— libs/partners/fireworks/langchain_fireworks/_compat.py:9-17 | libs/partners/openai/langchain_openai/chat_models/_compat.py:170-178 — before extracting anything, compare `libs/partners/fireworks/langchain_fireworks/_compat.py` and `libs/partners/openai/langchain_openai/chat_models/_compat.py` as WHOLE FILES: 85% of the shorter file's lines also appear in the other, so this reads as one file having been copied from the other rather than as a helper waiting to be extracted. The 2 duplicated block(s) this scan matched between them are fragments of that copy, not the extent of it — treat the file pair as the unit. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (9 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:4532— libs/partners/openai/langchain_openai/chat_models/base.py:4532-4540 | libs/partners/openai/langchain_openai/chat_models/base.py:4582-4590 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) libs/core/langchain_core/language_models/llms.py:1427— libs/core/langchain_core/language_models/llms.py:1427-1435 | libs/core/langchain_core/prompts/base.py:421-429 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (9 lines × 2) libs/langchain/langchain_classic/agents/loading.py:106— libs/langchain/langchain_classic/agents/loading.py:106-126 | libs/langchain/langchain_classic/chains/loading.py:703-711 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1558— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1558-1566 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1597-1605 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1567` calls `write` and `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1607` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (9 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1867— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1867-1875 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1890-1898 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) libs/core/langchain_core/language_models/chat_model_stream.py:829— libs/core/langchain_core/language_models/chat_model_stream.py:829-838 | libs/core/langchain_core/language_models/chat_model_stream.py:867-876 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) libs/core/langchain_core/runnables/base.py:5254— libs/core/langchain_core/runnables/base.py:5254-5263 | libs/core/langchain_core/runnables/base.py:5482-5491 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:5254` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) libs/core/langchain_core/utils/aiter.py:218— libs/core/langchain_core/utils/aiter.py:218-227 | libs/core/langchain_core/utils/iter.py:145-154 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (10 lines × 2) libs/core/langchain_core/vectorstores/in_memory.py:197— libs/core/langchain_core/vectorstores/in_memory.py:197-206 | libs/core/langchain_core/vectorstores/in_memory.py:230-239 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note first that the copies are not typed on the same thing: the declarations holding them bind `ids` to `Sequence[str] | None = None` in one and `list[str] | None = None` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (10 lines × 2) libs/langchain/langchain_classic/chains/llm.py:136— libs/langchain/langchain_classic/chains/llm.py:136-145 | libs/langchain/langchain_classic/chains/llm.py:163-172 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/llm.py:136` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (10 lines × 2) libs/partners/anthropic/langchain_anthropic/chat_models.py:1683— libs/partners/anthropic/langchain_anthropic/chat_models.py:1683-1692 | libs/partners/mistralai/langchain_mistralai/chat_models.py:704-713 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (10 lines × 2) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:443— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:443-452 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:493-502 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:441` calls `get` and `libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:491` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 2) libs/partners/fireworks/langchain_fireworks/_compat.py:17— libs/partners/fireworks/langchain_fireworks/_compat.py:17-26 | libs/partners/openai/langchain_openai/chat_models/_compat.py:182-193 — before extracting anything, compare `libs/partners/fireworks/langchain_fireworks/_compat.py` and `libs/partners/openai/langchain_openai/chat_models/_compat.py` as WHOLE FILES: 85% of the shorter file's lines also appear in the other, so this reads as one file having been copied from the other rather than as a helper waiting to be extracted. The 2 duplicated block(s) this scan matched between them are fragments of that copy, not the extent of it — treat the file pair as the unit. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/partners/openai/langchain_openai/chat_models/_compat.py:181` calls `get` and `libs/partners/fireworks/langchain_fireworks/_compat.py:17` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 2) libs/partners/openai/langchain_openai/embeddings/base.py:746— libs/partners/openai/langchain_openai/embeddings/base.py:746-755 | libs/partners/openai/langchain_openai/embeddings/base.py:781-790 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openai/langchain_openai/embeddings/base.py:746` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 2) libs/partners/perplexity/langchain_perplexity/chat_models.py:1446— libs/partners/perplexity/langchain_perplexity/chat_models.py:1446-1455 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1513-1522 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) libs/langchain/langchain_classic/memory/summary.py:151— libs/langchain/langchain_classic/memory/summary.py:151-160 | libs/langchain/langchain_classic/memory/summary_buffer.py:90-99 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (10 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:966— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:966-975 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:981-990 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
D4 · Code Duplication· Members sharing a duplicated core (4 members, 50+ identical tokens) · ×11
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py:524— libs/core/langchain_core/language_models/chat_models.py:524-540 | libs/core/langchain_core/language_models/chat_models.py:551-564 | libs/core/langchain_core/language_models/llms.py:382-396 | libs/core/langchain_core/language_models/llms.py:407-418 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py:778— libs/core/langchain_core/language_models/chat_models.py:778-898 | libs/core/langchain_core/language_models/chat_models.py:909-1033 | libs/core/langchain_core/language_models/chat_models.py:1942-2092 | libs/core/langchain_core/language_models/chat_models.py:2101-2249 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/runnables/base.py:3533— libs/core/langchain_core/runnables/base.py:3533-3650 | libs/core/langchain_core/runnables/base.py:3661-3781 | libs/core/langchain_core/runnables/fallbacks.py:273-358 | libs/core/langchain_core/runnables/fallbacks.py:369-462 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/core/langchain_core/runnables/fallbacks.py:168— libs/core/langchain_core/runnables/fallbacks.py:168-212 | libs/core/langchain_core/runnables/fallbacks.py:221-262 | libs/core/langchain_core/runnables/fallbacks.py:471-526 | libs/core/langchain_core/runnables/fallbacks.py:535-590 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:175— libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:175-196 | libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py:147-168 | libs/langchain/langchain_classic/chains/combine_documents/refine.py:122-143 | libs/langchain/langchain_classic/chains/combine_documents/stuff.py:169-191 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain/langchain_classic/chains/loading.py:97— libs/langchain/langchain_classic/chains/loading.py:97-115 | libs/langchain/langchain_classic/chains/loading.py:366-392 | libs/langchain/langchain_classic/chains/loading.py:595-621 | libs/langchain/langchain_classic/chains/loading.py:625-650 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain/langchain_classic/chains/loading.py:433— libs/langchain/langchain_classic/chains/loading.py:433-459 | libs/langchain/langchain_classic/chains/loading.py:463-489 | libs/langchain/langchain_classic/chains/loading.py:496-522 | libs/langchain/langchain_classic/chains/loading.py:526-552 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain_v1/langchain/agents/middleware/model_retry.py:226— libs/langchain_v1/langchain/agents/middleware/model_retry.py:226-273 | libs/langchain_v1/langchain/agents/middleware/model_retry.py:280-327 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:300-357 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:364-421 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/langchain_v1/langchain/agents/middleware/types.py:965— libs/langchain_v1/langchain/agents/middleware/types.py:965-1121 | libs/langchain_v1/langchain/agents/middleware/types.py:1154-1298 | libs/langchain_v1/langchain/agents/middleware/types.py:1331-1510 | libs/langchain_v1/langchain/agents/middleware/types.py:1543-1688 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:294— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:294-317 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:324-347 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:788-811 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:818-841 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:753— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:753-766 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:771-782 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:787-798 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:821-832 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
D4 · Code Duplication· Edited copy of a member (19 corresponding lines) · ×11
Edited copy of a member (19 corresponding lines) libs/langchain/langchain_classic/chains/llm.py:179— libs/langchain/langchain_classic/chains/llm.py:179-197 | libs/langchain/langchain_classic/chains/llm.py:204-222 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/langchain/langchain_classic/chains/router/base.py:98— libs/langchain/langchain_classic/chains/router/base.py:98-116 | libs/langchain/langchain_classic/chains/router/base.py:123-147 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/core/langchain_core/language_models/fake_chat_models.py:102— libs/core/langchain_core/language_models/fake_chat_models.py:102-121 | libs/core/langchain_core/language_models/fake_chat_models.py:131-149 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/partners/openai/langchain_openai/llms/base.py:397— libs/partners/openai/langchain_openai/llms/base.py:397-415 | libs/partners/openai/langchain_openai/llms/base.py:424-444 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/core/langchain_core/language_models/chat_model_stream.py:879— libs/core/langchain_core/language_models/chat_model_stream.py:879-918 | libs/core/langchain_core/language_models/chat_model_stream.py:921-939 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/langchain/langchain_classic/chains/llm.py:229— libs/langchain/langchain_classic/chains/llm.py:229-247 | libs/langchain/langchain_classic/chains/llm.py:254-272 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/core/langchain_core/utils/aiter.py:209— libs/core/langchain_core/utils/aiter.py:209-227 | libs/core/langchain_core/utils/iter.py:136-154 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/partners/perplexity/langchain_perplexity/chat_models.py:909— libs/partners/perplexity/langchain_perplexity/chat_models.py:909-927 | libs/partners/perplexity/langchain_perplexity/embeddings.py:107-128 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:2098— libs/partners/qdrant/langchain_qdrant/vectorstores.py:2098-2116 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2119-2137 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1641— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1641-1661 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1666-1684 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/indexer.py:94— libs/standard-tests/langchain_tests/integration_tests/indexer.py:94-112 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:284-304 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (18 corresponding lines) · ×11
Edited copy of a member (18 corresponding lines) libs/core/langchain_core/messages/block_translators/openai.py:271— libs/core/langchain_core/messages/block_translators/openai.py:271-288 | libs/partners/openai/langchain_openai/chat_models/_compat.py:170-193 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:459— libs/langchain/langchain_classic/indexes/_sql_record_manager.py:459-476 | libs/langchain/langchain_classic/indexes/_sql_record_manager.py:486-504 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/core/langchain_core/_security/_transport.py:206— libs/core/langchain_core/_security/_transport.py:206-223 | libs/core/langchain_core/_security/_transport.py:230-254 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/core/langchain_core/messages/function.py:45— libs/core/langchain_core/messages/function.py:45-62 | libs/core/langchain_core/messages/tool.py:184-203 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/langchain_v1/langchain/agents/middleware/model_call_limit.py:43— libs/langchain_v1/langchain/agents/middleware/model_call_limit.py:43-60 | libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py:78-102 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/core/langchain_core/tracers/log_stream.py:138— libs/core/langchain_core/tracers/log_stream.py:138-155 | libs/core/langchain_core/tracers/log_stream.py:186-203 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py:285— libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py:285-302 | libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py:309-326 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/partners/qdrant/langchain_qdrant/qdrant.py:532— libs/partners/qdrant/langchain_qdrant/qdrant.py:532-549 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:930-982 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/embeddings.py:61— libs/standard-tests/langchain_tests/integration_tests/embeddings.py:61-78 | libs/standard-tests/langchain_tests/integration_tests/embeddings.py:102-119 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:201— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:201-218 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1903-1923 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/indexer.py:115— libs/standard-tests/langchain_tests/integration_tests/indexer.py:115-132 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:307-324 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (20 lines × 2) libs/core/langchain_core/language_models/chat_models.py:2071— libs/core/langchain_core/language_models/chat_models.py:2071-2090 | libs/core/langchain_core/language_models/chat_models.py:2228-2247 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20 lines × 2) libs/core/langchain_core/messages/block_translators/anthropic.py:240— libs/core/langchain_core/messages/block_translators/anthropic.py:240-259 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:170-189 — before extracting anything, compare `libs/core/langchain_core/messages/block_translators/anthropic.py` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (20 lines × 2) libs/core/langchain_core/runnables/base.py:2536— libs/core/langchain_core/runnables/base.py:2536-2555 | libs/core/langchain_core/runnables/base.py:3762-3781 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3762` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20 lines × 2) libs/core/langchain_core/runnables/config.py:507— libs/core/langchain_core/runnables/config.py:507-526 | libs/core/langchain_core/runnables/config.py:541-560 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20 lines × 2) libs/core/langchain_core/runnables/fallbacks.py:168— libs/core/langchain_core/runnables/fallbacks.py:168-187 | libs/core/langchain_core/runnables/fallbacks.py:471-490 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20 lines × 2) libs/core/langchain_core/tracers/event_stream.py:1035— libs/core/langchain_core/tracers/event_stream.py:1035-1054 | libs/core/langchain_core/tracers/log_stream.py:695-714 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (20 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:887— libs/langchain/langchain_classic/chat_models/base.py:887-906 | libs/langchain_v1/langchain/chat_models/base.py:876-895 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (20 lines × 2) REDACTED:575— REDACTED:575-594 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:259-278 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20 lines × 2) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:428— libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:428-447 | libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:464-483 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:428` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (20 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1976— libs/partners/openai/langchain_openai/chat_models/base.py:1976-1995 | libs/partners/openai/langchain_openai/chat_models/base.py:2279-2298 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:864— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:864-883 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:917-936 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (19 lines × 2) libs/core/langchain_core/_api/beta_decorator.py:116— libs/core/langchain_core/_api/beta_decorator.py:116-134 | libs/core/langchain_core/_api/deprecation.py:250-268 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (19 lines × 2) libs/core/langchain_core/_api/beta_decorator.py:185— libs/core/langchain_core/_api/beta_decorator.py:185-203 | libs/core/langchain_core/_api/deprecation.py:389-407 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (19 lines × 2) libs/core/langchain_core/indexing/api.py:554— libs/core/langchain_core/indexing/api.py:554-572 | libs/core/langchain_core/indexing/api.py:903-923 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/indexing/api.py:554` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19 lines × 2) libs/core/langchain_core/runnables/branch.py:333— libs/core/langchain_core/runnables/branch.py:333-351 | libs/core/langchain_core/runnables/branch.py:417-435 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/branch.py:333` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) libs/core/langchain_core/tools/simple.py:106— libs/core/langchain_core/tools/simple.py:106-124 | libs/core/langchain_core/tools/structured.py:136-154 — before extracting anything, compare `libs/core/langchain_core/tools/simple.py` and `libs/core/langchain_core/tools/structured.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (19 lines × 2) libs/langchain/langchain_classic/chains/base.py:522— libs/langchain/langchain_classic/chains/base.py:522-540 | libs/langchain/langchain_classic/chains/base.py:546-564 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (19 lines × 2) libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:101— libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:101-119 | libs/langchain/langchain_classic/chains/summarize/chain.py:129-147 — before extracting anything, compare `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py` and `libs/langchain/langchain_classic/chains/summarize/chain.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 46 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:101` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:831— libs/langchain/langchain_classic/chat_models/base.py:831-849 | libs/langchain_v1/langchain/chat_models/base.py:820-838 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:859— libs/langchain/langchain_classic/chat_models/base.py:859-877 | libs/langchain_v1/langchain/chat_models/base.py:848-866 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:1443— libs/partners/groq/langchain_groq/chat_models.py:1443-1461 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:163-181 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/groq/langchain_groq/chat_models.py:1443` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19 lines × 2) libs/partners/openai/langchain_openai/decisions/base.py:171— libs/partners/openai/langchain_openai/decisions/base.py:171-189 | libs/partners/openai/langchain_openai/decisions/classifier.py:187-205 — before extracting anything, compare `libs/partners/openai/langchain_openai/decisions/base.py` and `libs/partners/openai/langchain_openai/decisions/classifier.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 37 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17 lines × 2) libs/core/langchain_core/language_models/chat_models.py:1942— libs/core/langchain_core/language_models/chat_models.py:1942-1958 | libs/core/langchain_core/language_models/chat_models.py:2101-2117 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) libs/core/langchain_core/language_models/chat_models.py:2025— libs/core/langchain_core/language_models/chat_models.py:2025-2041 | libs/core/langchain_core/language_models/chat_models.py:2180-2196 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) libs/core/langchain_core/language_models/llms.py:1056— libs/core/langchain_core/language_models/llms.py:1056-1072 | libs/core/langchain_core/language_models/llms.py:1335-1351 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/llms.py:1056` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17 lines × 2) libs/langchain/langchain_classic/agents/openai_assistant/base.py:527— libs/langchain/langchain_classic/agents/openai_assistant/base.py:527-543 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:684-700 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:754— libs/langchain/langchain_classic/chat_models/base.py:754-770 | libs/langchain_v1/langchain/chat_models/base.py:748-764 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 2) REDACTED:2029— REDACTED:2029-2045 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1042-1058 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2029` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1203— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1203-1219 | libs/partners/ollama/langchain_ollama/chat_models.py:1772-1788 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1203` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1457— libs/partners/openai/langchain_openai/chat_models/base.py:1457-1473 | libs/partners/openai/langchain_openai/embeddings/base.py:386-403 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (17 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:710— libs/partners/qdrant/langchain_qdrant/qdrant.py:710-726 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:434-479 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:1080— libs/partners/qdrant/langchain_qdrant/qdrant.py:1080-1096 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2027-2043 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1772— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1772-1788 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1817-1833 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2) libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:282— libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:282-294 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:473-484 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:282` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1910— libs/partners/openai/langchain_openai/chat_models/base.py:1910-1921 | libs/partners/openai/langchain_openai/chat_models/base.py:2211-2222 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) libs/partners/perplexity/langchain_perplexity/chat_models.py:1207— libs/partners/perplexity/langchain_perplexity/chat_models.py:1207-1218 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1324-1335 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2) libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:86— libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:86-97 | libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:130-141 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (12 lines × 2) libs/core/langchain_core/prompts/few_shot.py:56— libs/core/langchain_core/prompts/few_shot.py:56-79 | libs/core/langchain_core/prompts/few_shot_with_templates.py:66-77 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (12 lines × 2) libs/partners/anthropic/langchain_anthropic/chat_models.py:110— libs/partners/anthropic/langchain_anthropic/chat_models.py:110-121 | libs/partners/openai/langchain_openai/chat_models/base.py:753-764 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) libs/partners/openai/langchain_openai/decisions/base.py:208— libs/partners/openai/langchain_openai/decisions/base.py:208-219 | libs/partners/openai/langchain_openai/decisions/classifier.py:229-240 — before extracting anything, compare `libs/partners/openai/langchain_openai/decisions/base.py` and `libs/partners/openai/langchain_openai/decisions/classifier.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 37 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:3817— libs/partners/openai/langchain_openai/chat_models/base.py:3817-3829 | libs/partners/openai/langchain_openai/llms/base.py:907-918 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (12 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:181— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:181-192 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:201-212 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1726— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1726-1737 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1833-1844 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
D4 · Code Duplication· Edited copy of a member (27 corresponding lines) · ×9
Edited copy of a member (27 corresponding lines) libs/core/langchain_core/vectorstores/in_memory.py:194— libs/core/langchain_core/vectorstores/in_memory.py:194-221 | libs/core/langchain_core/vectorstores/in_memory.py:227-253 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/core/langchain_core/runnables/base.py:4112— libs/core/langchain_core/runnables/base.py:4112-4147 | libs/core/langchain_core/runnables/base.py:5120-5146 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain/langchain_classic/chains/loading.py:119— libs/langchain/langchain_classic/chains/loading.py:119-145 | libs/langchain/langchain_classic/chains/loading.py:152-182 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain/langchain_classic/retrievers/merger_retriever.py:58— libs/langchain/langchain_classic/retrievers/merger_retriever.py:58-84 | libs/langchain/langchain_classic/retrievers/merger_retriever.py:91-119 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:624— libs/langchain/langchain_classic/chat_models/base.py:624-650 | libs/langchain_v1/langchain/chat_models/base.py:624-651 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:2140— libs/partners/qdrant/langchain_qdrant/vectorstores.py:2140-2166 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2169-2195 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:986— libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:986-1012 | libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:1019-1045 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:378— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:378-408 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:385-411 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:332— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:332-362 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:344-370 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (12 corresponding lines) · ×9
Edited copy of a member (12 corresponding lines) libs/core/langchain_core/language_models/chat_models.py:1496— libs/core/langchain_core/language_models/chat_models.py:1496-1514 | libs/core/langchain_core/language_models/chat_models.py:1523-1534 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/base.py:136— libs/langchain/langchain_classic/chains/combine_documents/base.py:136-147 | libs/langchain/langchain_classic/chains/combine_documents/base.py:154-165 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/core/langchain_core/language_models/chat_model_stream.py:89— libs/core/langchain_core/language_models/chat_model_stream.py:89-103 | libs/standard-tests/langchain_tests/utils/stream_lifecycle.py:171-182 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py:284— libs/partners/mistralai/langchain_mistralai/chat_models.py:284-295 | libs/partners/mistralai/langchain_mistralai/chat_models.py:299-310 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/core/langchain_core/tracers/base.py:732— libs/core/langchain_core/tracers/base.py:732-744 | libs/core/langchain_core/tracers/base.py:794-805 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py:1776— libs/partners/anthropic/langchain_anthropic/chat_models.py:1776-1787 | libs/partners/anthropic/langchain_anthropic/chat_models.py:1791-1802 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/partners/anthropic/langchain_anthropic/llms.py:111— libs/partners/anthropic/langchain_anthropic/llms.py:111-122 | REDACTED:1308-1324 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/langchain_v1/langchain/agents/middleware/auto_mode.py:147— libs/langchain_v1/langchain/agents/middleware/auto_mode.py:147-158 | libs/partners/openai/langchain_openai/middleware/auto_mode.py:205-219 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:165— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:165-176 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1860-1875 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (18 lines × 2) libs/core/langchain_core/messages/block_translators/google_genai.py:340— libs/core/langchain_core/messages/block_translators/google_genai.py:340-357 | libs/core/langchain_core/messages/block_translators/google_genai.py:554-571 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) libs/core/langchain_core/runnables/base.py:4573— libs/core/langchain_core/runnables/base.py:4573-4590 | libs/core/langchain_core/runnables/base.py:4614-4631 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) libs/core/langchain_core/runnables/branch.py:353— libs/core/langchain_core/runnables/branch.py:353-370 | libs/core/langchain_core/runnables/branch.py:437-454 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/branch.py:353` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18 lines × 2) libs/langchain/langchain_classic/agents/agent.py:1354— libs/langchain/langchain_classic/agents/agent.py:1354-1371 | libs/langchain/langchain_classic/agents/agent.py:1491-1508 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/agent.py:1354` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (18 lines × 2) libs/langchain_v1/langchain/agents/middleware/file_search.py:79— libs/langchain_v1/langchain/agents/middleware/file_search.py:79-96 | libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:60-77 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/file_search.py` and `libs/partners/anthropic/langchain_anthropic/middleware/file_search.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 55 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (18 lines × 2) REDACTED:1346— REDACTED:1346-1363 | libs/partners/openai/langchain_openai/chat_models/base.py:1599-1616 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (18 lines × 2) REDACTED:1992— REDACTED:1992-2009 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1005-1022 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1992` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:1567— libs/partners/groq/langchain_groq/chat_models.py:1567-1584 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1374-1391 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/partners/groq/langchain_groq/chat_models.py:1585` calls `FunctionMessage`, `get` and `libs/partners/openrouter/langchain_openrouter/chat_models.py:1392` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (18 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2332— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2332-2349 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2414-2431 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2332` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) libs/core/langchain_core/tracers/core.py:330— libs/core/langchain_core/tracers/core.py:330-342 | libs/core/langchain_core/tracers/core.py:379-391 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note first that the copies are not typed on the same thing: the declarations holding them bind `response` to `LLMResult` in one and `LLMResult | None = None` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/tracers/core.py:392` calls `_attach_gateway_metadata` and `libs/core/langchain_core/tracers/core.py:343` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (13 lines × 2) libs/langchain/langchain_classic/agents/openai_assistant/base.py:330— libs/langchain/langchain_classic/agents/openai_assistant/base.py:330-342 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:462-474 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) libs/langchain/langchain_classic/chains/llm.py:179— libs/langchain/langchain_classic/chains/llm.py:179-191 | libs/langchain/langchain_classic/chains/llm.py:204-216 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `run_manager` to `CallbackManagerForChainRun | None = None` in one and `AsyncCallbackManagerForChainRun | None = None` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (13 lines × 2) libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:165— libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:165-177 | libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:185-197 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) libs/partners/anthropic/langchain_anthropic/_compat.py:41— libs/partners/anthropic/langchain_anthropic/_compat.py:41-53 | libs/partners/anthropic/langchain_anthropic/_compat.py:85-97 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:1040— libs/langchain/langchain_classic/chat_models/base.py:1040-1052 | libs/langchain_v1/langchain/chat_models/base.py:1031-1043 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (13 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1712— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1712-1724 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1791-1803 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1648— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1648-1660 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1672-1684 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1647` calls `write` and `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1671` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (13 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1689— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1689-1701 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1744-1756 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
D4 · Code Duplication· Edited copy of a member (28 corresponding lines) · ×8
Edited copy of a member (28 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py:1298— libs/partners/anthropic/langchain_anthropic/chat_models.py:1298-1328 | libs/partners/openai/langchain_openai/chat_models/base.py:722-749 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/langchain/langchain_classic/agents/chat/output_parser.py:28— libs/langchain/langchain_classic/agents/chat/output_parser.py:28-67 | libs/langchain/langchain_classic/agents/output_parsers/react_json_single_input.py:55-82 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:425— libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:425-453 | libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:462-489 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/core/langchain_core/language_models/llms.py:164— libs/core/langchain_core/language_models/llms.py:164-192 | libs/core/langchain_core/language_models/llms.py:200-227 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:55— libs/partners/openai/langchain_openai/chat_models/_client_utils.py:55-83 | libs/partners/openai/langchain_openai/chat_models/_client_utils.py:87-114 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/core/langchain_core/runnables/base.py:6226— libs/core/langchain_core/runnables/base.py:6226-6255 | libs/core/langchain_core/runnables/base.py:6308-6335 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/core/langchain_core/runnables/base.py:526— libs/core/langchain_core/runnables/base.py:526-561 | libs/core/langchain_core/runnables/history.py:424-451 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:939— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:939-970 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:973-1000 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (16 corresponding lines) · ×8
Edited copy of a member (16 corresponding lines) libs/core/langchain_core/vectorstores/base.py:1044— libs/core/langchain_core/vectorstores/base.py:1044-1059 | libs/core/langchain_core/vectorstores/base.py:1069-1086 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/core/langchain_core/indexing/api.py:251— libs/core/langchain_core/indexing/api.py:251-277 | libs/core/langchain_core/indexing/api.py:617-632 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/partners/typesafe/langchain_typesafe/classifier.py:305— libs/partners/typesafe/langchain_typesafe/classifier.py:305-320 | libs/partners/typesafe/langchain_typesafe/classifier.py:326-341 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/langchain/langchain_classic/memory/summary_buffer.py:52— libs/langchain/langchain_classic/memory/summary_buffer.py:52-67 | libs/langchain/langchain_classic/memory/summary_buffer.py:71-86 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:87— libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:87-102 | libs/langchain/langchain_classic/callbacks/streaming_stdout_final_only.py:82-100 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/core/langchain_core/callbacks/manager.py:590— libs/core/langchain_core/callbacks/manager.py:590-605 | libs/core/langchain_core/callbacks/manager.py:674-689 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py:483— libs/partners/mistralai/langchain_mistralai/chat_models.py:483-498 | libs/partners/mistralai/langchain_mistralai/chat_models.py:502-531 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:981— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:981-997 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1002-1017 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (15 corresponding lines) · ×8
Edited copy of a member (15 corresponding lines) libs/core/langchain_core/runnables/base.py:3790— libs/core/langchain_core/runnables/base.py:3790-3804 | libs/core/langchain_core/runnables/base.py:3813-3829 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py:672— libs/partners/groq/langchain_groq/chat_models.py:672-686 | libs/partners/groq/langchain_groq/chat_models.py:695-710 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/core/langchain_core/runnables/history.py:549— libs/core/langchain_core/runnables/history.py:549-563 | libs/core/langchain_core/runnables/history.py:566-580 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/core/langchain_core/runnables/graph.py:712— libs/core/langchain_core/runnables/graph.py:712-726 | libs/core/langchain_core/runnables/graph.py:730-744 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/core/langchain_core/indexing/api.py:105— libs/core/langchain_core/indexing/api.py:105-119 | libs/core/langchain_core/utils/aiter.py:328-357 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:434— libs/partners/openai/langchain_openai/chat_models/_client_utils.py:434-456 | libs/partners/openai/langchain_openai/chat_models/_client_utils.py:464-478 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/langchain_v1/langchain/agents/middleware/model_call_limit.py:77— libs/langchain_v1/langchain/agents/middleware/model_call_limit.py:77-91 | libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py:120-138 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:888— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:888-902 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:907-924 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (16 lines × 2) libs/core/langchain_core/language_models/chat_models.py:1997— libs/core/langchain_core/language_models/chat_models.py:1997-2012 | libs/core/langchain_core/language_models/chat_models.py:2152-2167 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_models.py:1997` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) libs/core/langchain_core/runnables/base.py:3457— libs/core/langchain_core/runnables/base.py:3457-3472 | libs/core/langchain_core/runnables/base.py:3496-3511 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3457` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) libs/langchain/langchain_classic/chains/qa_with_sources/retrieval.py:29— libs/langchain/langchain_classic/chains/qa_with_sources/retrieval.py:29-44 | libs/langchain/langchain_classic/chains/qa_with_sources/vector_db.py:35-50 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (16 lines × 2) libs/partners/ollama/langchain_ollama/llms.py:514— libs/partners/ollama/langchain_ollama/llms.py:514-529 | libs/partners/ollama/langchain_ollama/llms.py:545-560 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (16 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1877— libs/partners/openai/langchain_openai/chat_models/base.py:1877-1892 | libs/partners/openai/langchain_openai/chat_models/base.py:2172-2187 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/partners/openai/langchain_openai/chat_models/base.py:1876` calls `_ensure_sync_client_available` and `libs/partners/openai/langchain_openai/chat_models/base.py:2171` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (16 lines × 2) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:292— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:292-307 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:329-344 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:503— libs/partners/qdrant/langchain_qdrant/qdrant.py:503-518 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:154-180 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (16 lines × 2) libs/standard-tests/langchain_tests/integration_tests/indexer.py:50— libs/standard-tests/langchain_tests/integration_tests/indexer.py:50-65 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:240-255 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) libs/core/langchain_core/language_models/chat_models.py:503— libs/core/langchain_core/language_models/chat_models.py:503-513 | libs/core/langchain_core/language_models/llms.py:322-332 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) libs/core/langchain_core/language_models/chat_models.py:551— libs/core/langchain_core/language_models/chat_models.py:551-561 | libs/core/langchain_core/language_models/llms.py:407-417 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (11 lines × 2) libs/core/langchain_core/language_models/fake_chat_models.py:110— libs/core/langchain_core/language_models/fake_chat_models.py:110-121 | libs/core/langchain_core/language_models/fake_chat_models.py:139-149 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) libs/core/langchain_core/messages/block_translators/google_genai.py:157— libs/core/langchain_core/messages/block_translators/google_genai.py:157-167 | libs/core/langchain_core/messages/block_translators/google_genai.py:207-217 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) libs/core/langchain_core/runnables/branch.py:311— libs/core/langchain_core/runnables/branch.py:311-321 | libs/core/langchain_core/runnables/branch.py:395-405 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/branch.py:311` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) libs/core/langchain_core/runnables/retry.py:247— libs/core/langchain_core/runnables/retry.py:247-257 | libs/core/langchain_core/runnables/retry.py:323-333 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) libs/langchain/langchain_classic/agents/chat/base.py:56— libs/langchain/langchain_classic/agents/chat/base.py:56-66 | libs/langchain/langchain_classic/agents/structured_chat/base.py:61-71 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1089— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1089-1099 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1119-1129 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
D4 · Code Duplication· Edited copy of a member (29 corresponding lines) · ×7
Edited copy of a member (29 corresponding lines) libs/core/langchain_core/language_models/chat_models.py:1550— libs/core/langchain_core/language_models/chat_models.py:1550-1609 | libs/core/langchain_core/language_models/llms.py:339-371 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/core/langchain_core/prompts/chat.py:590— libs/core/langchain_core/prompts/chat.py:590-618 | libs/core/langchain_core/prompts/chat.py:621-649 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/core/langchain_core/runnables/configurable.py:163— libs/core/langchain_core/runnables/configurable.py:163-195 | libs/core/langchain_core/runnables/configurable.py:206-234 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/core/langchain_core/runnables/utils.py:737— libs/core/langchain_core/runnables/utils.py:737-765 | libs/core/langchain_core/tracers/log_stream.py:388-424 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/core/langchain_core/runnables/base.py:2334— libs/core/langchain_core/runnables/base.py:2334-2370 | libs/core/langchain_core/runnables/base.py:2385-2413 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/langchain/langchain_classic/chains/retrieval_qa/base.py:134— libs/langchain/langchain_classic/chains/retrieval_qa/base.py:134-162 | libs/langchain/langchain_classic/chains/retrieval_qa/base.py:178-206 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (29 corresponding lines) libs/langchain/langchain_classic/agents/chat/base.py:92— libs/langchain/langchain_classic/agents/chat/base.py:92-120 | libs/langchain/langchain_classic/agents/conversational/base.py:85-113 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (31 corresponding lines) · ×7
Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/reduce.py:316— libs/langchain/langchain_classic/chains/combine_documents/reduce.py:316-346 | libs/langchain/langchain_classic/chains/combine_documents/reduce.py:355-385 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/agents/agent.py:1387— libs/langchain/langchain_classic/agents/agent.py:1387-1417 | libs/langchain/langchain_classic/agents/agent.py:1534-1568 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/retrievers/multi_vector.py:83— libs/langchain/langchain_classic/retrievers/multi_vector.py:83-113 | libs/langchain/langchain_classic/retrievers/multi_vector.py:122-155 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) libs/langchain_v1/langchain/agents/middleware/file_search.py:45— libs/langchain_v1/langchain/agents/middleware/file_search.py:45-75 | libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:24-56 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) libs/partners/openai/langchain_openai/embeddings/base.py:727— libs/partners/openai/langchain_openai/embeddings/base.py:727-758 | libs/partners/openai/langchain_openai/embeddings/base.py:763-793 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) .github/scripts/get_min_versions.py:61— .github/scripts/get_min_versions.py:61-95 | .github/scripts/get_min_versions.py:169-199 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) libs/langchain/langchain_classic/chains/openai_functions/base.py:158— libs/langchain/langchain_classic/chains/openai_functions/base.py:158-239 | libs/langchain/langchain_classic/chains/structured_output/base.py:505-535 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (17 corresponding lines) · ×7
Edited copy of a member (17 corresponding lines) libs/langchain/langchain_classic/chains/llm_math/base.py:227— libs/langchain/langchain_classic/chains/llm_math/base.py:227-243 | libs/langchain/langchain_classic/chains/llm_math/base.py:250-266 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/langchain/langchain_classic/chains/sequential.py:168— libs/langchain/langchain_classic/chains/sequential.py:168-184 | libs/langchain/langchain_classic/chains/sequential.py:191-207 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/langchain/langchain_classic/agents/xml/base.py:71— libs/langchain/langchain_classic/agents/xml/base.py:71-87 | libs/langchain/langchain_classic/agents/xml/base.py:96-112 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/core/langchain_core/runnables/base.py:3381— libs/core/langchain_core/runnables/base.py:3381-3397 | libs/core/langchain_core/runnables/base.py:3430-3446 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/partners/ollama/langchain_ollama/chat_models.py:1145— libs/partners/ollama/langchain_ollama/chat_models.py:1145-1161 | libs/partners/ollama/langchain_ollama/chat_models.py:1171-1187 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/langchain/langchain_classic/retrievers/multi_query.py:121— libs/langchain/langchain_classic/retrievers/multi_query.py:121-137 | libs/langchain/langchain_classic/retrievers/multi_query.py:190-206 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/indexer.py:37— libs/standard-tests/langchain_tests/integration_tests/indexer.py:37-65 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:227-255 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (13 corresponding lines) · ×7
Edited copy of a member (13 corresponding lines) libs/partners/openai/langchain_openai/decisions/_input.py:99— libs/partners/openai/langchain_openai/decisions/_input.py:99-111 | libs/partners/typesafe/langchain_typesafe/_state.py:16-28 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py:2617— libs/partners/anthropic/langchain_anthropic/chat_models.py:2617-2629 | libs/partners/anthropic/langchain_anthropic/chat_models.py:2638-2650 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/partners/openai/langchain_openai/decisions/_classifier_input.py:337— libs/partners/openai/langchain_openai/decisions/_classifier_input.py:337-349 | libs/partners/openai/langchain_openai/decisions/_input.py:59-74 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/core/langchain_core/runnables/base.py:6029— libs/core/langchain_core/runnables/base.py:6029-6041 | libs/core/langchain_core/runnables/base.py:6052-6064 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:84— libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:84-96 | libs/langchain/langchain_classic/retrievers/time_weighted_retriever.py:99-113 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/langchain/langchain_classic/agents/__init__.py:100— libs/langchain/langchain_classic/agents/__init__.py:100-118 | libs/langchain/langchain_classic/agents/agent_toolkits/__init__.py:119-131 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:569— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:569-581 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:586-607 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (23 corresponding lines) · ×7
Edited copy of a member (23 corresponding lines) REDACTED:1344— REDACTED:1344-1372 | libs/partners/openai/langchain_openai/chat_models/base.py:1598-1620 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) REDACTED:1464— REDACTED:1464-1486 | REDACTED:1611-1634 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) libs/partners/ollama/langchain_ollama/llms.py:512— libs/partners/ollama/langchain_ollama/llms.py:512-534 | libs/partners/ollama/langchain_ollama/llms.py:543-565 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/base.py:29— libs/langchain/langchain_classic/retrievers/document_compressors/base.py:29-51 | libs/langchain/langchain_classic/retrievers/document_compressors/base.py:59-81 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) libs/langchain/langchain_classic/agents/agent_iterator.py:322— libs/langchain/langchain_classic/agents/agent_iterator.py:322-344 | libs/langchain/langchain_classic/agents/agent_iterator.py:351-373 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:181— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:181-203 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:208-230 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:704— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:704-727 | libs/partners/mistralai/langchain_mistralai/chat_models.py:863-885 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (7 lines × 2) libs/core/langchain_core/_security/_transport.py:62— libs/core/langchain_core/_security/_transport.py:62-70 | libs/core/langchain_core/_security/_transport.py:148-154 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2) libs/core/langchain_core/language_models/chat_models.py:1744— libs/core/langchain_core/language_models/chat_models.py:1744-1750 | libs/core/langchain_core/language_models/chat_models.py:1890-1896 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2) libs/core/langchain_core/prompts/chat.py:600— libs/core/langchain_core/prompts/chat.py:600-606 | libs/core/langchain_core/prompts/chat.py:631-637 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) libs/partners/anthropic/langchain_anthropic/_compat.py:10— libs/partners/anthropic/langchain_anthropic/_compat.py:10-16 | libs/partners/openai/langchain_openai/chat_models/_compat.py:79-85 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:1030— libs/partners/qdrant/langchain_qdrant/qdrant.py:1030-1036 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2053-2059 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) libs/partners/chroma/langchain_chroma/vectorstores.py:100— libs/partners/chroma/langchain_chroma/vectorstores.py:100-106 | libs/partners/qdrant/langchain_qdrant/_utils.py:62-68 — before extracting anything, compare `libs/partners/chroma/langchain_chroma/vectorstores.py` and `libs/partners/qdrant/langchain_qdrant/_utils.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 61 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (7 lines × 2) libs/partners/openai/langchain_openai/decisions/_classifier_input.py:205— libs/partners/openai/langchain_openai/decisions/_classifier_input.py:205-211 | libs/partners/openai/langchain_openai/decisions/_input.py:88-94 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
TooManyMethods: Runnable libs/core/langchain_core/runnables/base.py:197— TooManyMethods — 60 methods. The bar is 30 methods; this is 30 over it, 2.00× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: BaseChatModel libs/core/langchain_core/language_models/chat_models.py:325— TooManyMethods — 46 methods. The bar is 30 methods; this is 16 over it, 1.53× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: _TracerCore libs/core/langchain_core/tracers/core.py:66— TooManyMethods — 44 methods. The bar is 30 methods; this is 14 over it, 1.47× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: Qdrant libs/partners/qdrant/langchain_qdrant/vectorstores.py:60— TooManyMethods — 39 methods. The bar is 30 methods; this is 9 over it, 1.30× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: AsyncBaseTracer libs/core/langchain_core/tracers/base.py:551— TooManyMethods — 34 methods. The bar is 30 methods; this is 4 over it, 1.13× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: VectorStore libs/core/langchain_core/vectorstores/base.py:44— TooManyMethods — 34 methods. The bar is 30 methods; this is 4 over it, 1.13× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
D4 · Code Duplication· Edited copy of a member (33 corresponding lines) · ×6
Edited copy of a member (33 corresponding lines) libs/partners/ollama/langchain_ollama/llms.py:391— libs/partners/ollama/langchain_ollama/llms.py:391-423 | libs/partners/ollama/langchain_ollama/llms.py:433-465 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) libs/partners/openai/langchain_openai/middleware/openai_moderation.py:275— libs/partners/openai/langchain_openai/middleware/openai_moderation.py:275-307 | libs/partners/openai/langchain_openai/middleware/openai_moderation.py:312-344 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) libs/core/langchain_core/messages/block_translators/langchain_v0.py:11— libs/core/langchain_core/messages/block_translators/langchain_v0.py:11-43 | libs/core/langchain_core/messages/block_translators/openai.py:186-228 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:442— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:442-474 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:442-484 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) libs/partners/mistralai/langchain_mistralai/embeddings.py:252— libs/partners/mistralai/langchain_mistralai/embeddings.py:252-286 | libs/partners/mistralai/langchain_mistralai/embeddings.py:289-321 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py:825— libs/partners/chroma/langchain_chroma/vectorstores.py:825-857 | libs/partners/chroma/langchain_chroma/vectorstores.py:867-902 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (34 corresponding lines) · ×6
Edited copy of a member (34 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:248— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:248-281 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:249-294 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) libs/core/langchain_core/runnables/passthrough.py:550— libs/core/langchain_core/runnables/passthrough.py:550-588 | libs/core/langchain_core/runnables/passthrough.py:609-642 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) libs/langchain/langchain_classic/embeddings/cache.py:166— libs/langchain/langchain_classic/embeddings/cache.py:166-199 | libs/langchain/langchain_classic/embeddings/cache.py:202-239 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) libs/partners/qdrant/langchain_qdrant/qdrant.py:460— libs/partners/qdrant/langchain_qdrant/qdrant.py:460-493 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2294-2332 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) libs/langchain/langchain_classic/retrievers/ensemble.py:225— libs/langchain/langchain_classic/retrievers/ensemble.py:225-258 | libs/langchain/langchain_classic/retrievers/ensemble.py:267-302 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) libs/partners/deepseek/langchain_deepseek/chat_models.py:542— libs/partners/deepseek/langchain_deepseek/chat_models.py:542-575 | libs/partners/deepseek/langchain_deepseek/chat_models.py:590-680 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (24 corresponding lines) · ×6
Edited copy of a member (24 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:55— libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:55-79 | libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:87-110 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) libs/core/langchain_core/vectorstores/base.py:236— libs/core/langchain_core/vectorstores/base.py:236-264 | libs/core/langchain_core/vectorstores/base.py:269-292 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) libs/langchain_v1/langchain/agents/middleware/_redaction.py:72— libs/langchain_v1/langchain/agents/middleware/_redaction.py:72-95 | libs/langchain_v1/langchain/agents/middleware/_redaction.py:99-125 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) libs/core/langchain_core/utils/utils.py:119— libs/core/langchain_core/utils/utils.py:119-143 | libs/langchain_v1/langchain/chat_models/base.py:126-149 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/indexer.py:135— libs/standard-tests/langchain_tests/integration_tests/indexer.py:135-158 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:327-350 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/indexer.py:68— libs/standard-tests/langchain_tests/integration_tests/indexer.py:68-91 | libs/standard-tests/langchain_tests/integration_tests/indexer.py:258-281 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (25 corresponding lines) · ×6
Edited copy of a member (25 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:843— libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:843-867 | libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1005-1029 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (25 corresponding lines) libs/partners/anthropic/langchain_anthropic/llms.py:246— libs/partners/anthropic/langchain_anthropic/llms.py:246-287 | libs/partners/anthropic/langchain_anthropic/llms.py:300-324 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (25 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/reduce.py:72— libs/langchain/langchain_classic/chains/combine_documents/reduce.py:72-96 | libs/langchain/langchain_classic/chains/combine_documents/reduce.py:104-128 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (25 corresponding lines) libs/core/langchain_core/tools/render.py:14— libs/core/langchain_core/tools/render.py:14-38 | libs/core/langchain_core/tools/render.py:42-67 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (25 corresponding lines) libs/langchain/langchain_classic/chains/openai_functions/extraction.py:63— libs/langchain/langchain_classic/chains/openai_functions/extraction.py:63-87 | libs/langchain/langchain_classic/chains/openai_functions/tagging.py:51-103 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (25 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/tools.py:13— libs/standard-tests/langchain_tests/integration_tests/tools.py:13-43 | libs/standard-tests/langchain_tests/integration_tests/tools.py:46-70 — These two members are one piece of code written twice and then edited apart: 25 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (24 lines × 2) libs/core/langchain_core/messages/block_translators/anthropic.py:77— libs/core/langchain_core/messages/block_translators/anthropic.py:77-100 | libs/core/langchain_core/messages/block_translators/anthropic.py:129-152 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `source` to `dict) and "type" in` in one and `block_type == "image" and isinstance(source, dict) and "type" in` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (24 lines × 2) libs/core/langchain_core/tools/base.py:1049— libs/core/langchain_core/tools/base.py:1049-1072 | libs/core/langchain_core/tools/base.py:1177-1200 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/tools/base.py:1049` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:916— libs/langchain/langchain_classic/chat_models/base.py:916-939 | libs/langchain_v1/langchain/chat_models/base.py:905-928 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (24 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1736— libs/partners/openai/langchain_openai/chat_models/base.py:1736-1759 | libs/partners/openai/langchain_openai/chat_models/base.py:1812-1835 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (24 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:604— libs/partners/qdrant/langchain_qdrant/vectorstores.py:604-627 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:699-722 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/qdrant/langchain_qdrant/vectorstores.py:604` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (24 lines × 2) libs/core/langchain_core/messages/human.py:37— libs/core/langchain_core/messages/human.py:37-60 | libs/core/langchain_core/messages/system.py:37-60 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/human.py:37` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
X17 · Uncapped recursion over a caller-supplied document· Recursive walk over a caller-supplied document has no depth cap · ×6
Recursive walk over a caller-supplied document has no depth cap libs/text-splitters/langchain_text_splitters/json.py:75— `split_json` is public, takes a document from its caller (line 116) and hands it to `_list_to_dict_preprocessing`, which calls itself at line 75 (`self._list_to_dict_preprocessing`) with a piece of `data` (and at line 79) — and nowhere in `_list_to_dict_preprocessing` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_list_to_dict_preprocessing` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap libs/partners/typesafe/langchain_typesafe/_assets.py:43— `replace` is public and takes `value: JsonValue` from its caller, and it calls itself at line 43 (`self.replace`) with a piece of `value` (and at line 45) — and nowhere in `replace` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `replace` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap libs/core/langchain_core/utils/_merge.py:66— `merge_dicts` is public and takes `left: dict[str, Any]` from its caller, and it calls itself at line 66 (`merge_dicts`) with a piece of `left` — and nowhere in `merge_dicts` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `merge_dicts` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap libs/core/langchain_core/utils/json_schema.py:136— `dereference_refs` is public, takes a document from its caller (line 188) and hands it to `_dereference_refs_helper`, which calls itself at line 136 (`_dereference_refs_helper`) with a piece of `obj` (and at line 178) — and nowhere in `_dereference_refs_helper` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_dereference_refs_helper` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap libs/core/langchain_core/utils/strings.py:21— `stringify_value` is public and takes `val: Any` from its caller, and it calls itself at line 21 (`stringify_value`) with a piece of `val` — and nowhere in `stringify_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `stringify_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap libs/core/langchain_core/runnables/graph_png.py:190— `add_subgraph` is public and takes `viz: Any` from its caller, and it calls itself at line 190 (`self.add_subgraph`) with a piece of `viz` — and nowhere in `add_subgraph` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `add_subgraph` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
D4 · Code Duplication· Edited copy of a member (36 corresponding lines) · ×5
Edited copy of a member (36 corresponding lines) libs/core/langchain_core/language_models/llms.py:429— libs/core/langchain_core/language_models/llms.py:429-465 | libs/core/langchain_core/language_models/llms.py:476-511 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (36 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:62— libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:62-97 | libs/langchain/langchain_classic/retrievers/document_compressors/embeddings_filter.py:106-141 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (36 corresponding lines) libs/langchain_v1/langchain/agents/middleware/summarization.py:482— libs/langchain_v1/langchain/agents/middleware/summarization.py:482-517 | libs/langchain_v1/langchain/agents/middleware/summarization.py:523-558 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (36 corresponding lines) libs/langchain_v1/langchain/agents/middleware/model_fallback.py:395— libs/langchain_v1/langchain/agents/middleware/model_fallback.py:395-430 | libs/langchain_v1/langchain/agents/middleware/model_fallback.py:437-472 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (36 corresponding lines) libs/core/langchain_core/callbacks/manager.py:1632— libs/core/langchain_core/callbacks/manager.py:1632-1667 | libs/core/langchain_core/callbacks/manager.py:2113-2148 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (46 corresponding lines) · ×5
Edited copy of a member (46 corresponding lines) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:837— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:837-895 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:906-951 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (46 corresponding lines) libs/langchain/langchain_classic/chains/base.py:137— libs/langchain/langchain_classic/chains/base.py:137-184 | libs/langchain/langchain_classic/chains/base.py:193-238 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (46 corresponding lines) libs/core/langchain_core/runnables/base.py:4162— libs/core/langchain_core/runnables/base.py:4162-4215 | libs/core/langchain_core/runnables/base.py:4225-4270 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (46 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:877— libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:877-922 | libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1039-1086 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (46 corresponding lines) libs/core/langchain_core/utils/aiter.py:111— libs/core/langchain_core/utils/aiter.py:111-158 | libs/core/langchain_core/utils/iter.py:43-88 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (32 corresponding lines) · ×5
Edited copy of a member (32 corresponding lines) libs/partners/mistralai/langchain_mistralai/chat_models.py:1379— libs/partners/mistralai/langchain_mistralai/chat_models.py:1379-1410 | libs/partners/openai/langchain_openai/chat_models/base.py:4426-4460 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) libs/core/langchain_core/runnables/base.py:5182— libs/core/langchain_core/runnables/base.py:5182-5213 | libs/core/langchain_core/runnables/base.py:5367-5412 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) libs/langchain_v1/langchain/agents/middleware/summarization.py:914— libs/langchain_v1/langchain/agents/middleware/summarization.py:914-946 | libs/langchain_v1/langchain/agents/middleware/summarization.py:949-980 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py:952— libs/partners/chroma/langchain_chroma/vectorstores.py:952-984 | libs/partners/chroma/langchain_chroma/vectorstores.py:993-1024 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) libs/core/langchain_core/example_selectors/semantic_similarity.py:288— libs/core/langchain_core/example_selectors/semantic_similarity.py:288-319 | libs/core/langchain_core/example_selectors/semantic_similarity.py:335-366 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (30 corresponding lines) · ×5
Edited copy of a member (30 corresponding lines) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:737— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:737-768 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:778-807 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (30 corresponding lines) libs/core/langchain_core/runnables/base.py:3453— libs/core/langchain_core/runnables/base.py:3453-3482 | libs/core/langchain_core/runnables/base.py:3492-3522 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (30 corresponding lines) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:189— libs/langchain/langchain_classic/indexes/_sql_record_manager.py:189-218 | libs/langchain/langchain_classic/indexes/_sql_record_manager.py:221-251 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (30 corresponding lines) libs/langchain_v1/langchain/agents/middleware/tool_error.py:138— libs/langchain_v1/langchain/agents/middleware/tool_error.py:138-173 | libs/langchain_v1/langchain/agents/middleware/tool_error.py:180-209 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (30 corresponding lines) libs/core/langchain_core/vectorstores/base.py:295— libs/core/langchain_core/vectorstores/base.py:295-325 | libs/core/langchain_core/vectorstores/base.py:330-359 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (10 corresponding lines) · ×5
Edited copy of a member (10 corresponding lines) libs/core/langchain_core/language_models/llms.py:1538— libs/core/langchain_core/language_models/llms.py:1538-1547 | libs/core/langchain_core/language_models/llms.py:1556-1565 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) libs/partners/openrouter/langchain_openrouter/chat_models.py:563— libs/partners/openrouter/langchain_openrouter/chat_models.py:563-572 | libs/partners/openrouter/langchain_openrouter/chat_models.py:581-590 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) libs/core/langchain_core/runnables/retry.py:193— libs/core/langchain_core/runnables/retry.py:193-202 | libs/core/langchain_core/runnables/retry.py:217-226 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) libs/core/langchain_core/indexing/api.py:92— libs/core/langchain_core/indexing/api.py:92-101 | libs/core/langchain_core/utils/iter.py:207-229 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/base_store.py:153— libs/standard-tests/langchain_tests/integration_tests/base_store.py:153-162 | libs/standard-tests/langchain_tests/integration_tests/base_store.py:304-315 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (6 corresponding lines) · ×5
Edited copy of a member (6 corresponding lines) libs/core/langchain_core/prompts/few_shot.py:101— libs/core/langchain_core/prompts/few_shot.py:101-117 | libs/core/langchain_core/prompts/few_shot_with_templates.py:117-122 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) libs/core/langchain_core/prompts/few_shot.py:82— libs/core/langchain_core/prompts/few_shot.py:82-98 | libs/core/langchain_core/prompts/few_shot_with_templates.py:109-114 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) libs/langchain/langchain_classic/agents/agent.py:746— libs/langchain/langchain_classic/agents/agent.py:746-751 | libs/langchain/langchain_classic/agents/format_scratchpad/log.py:9-23 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:430— libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:430-435 | libs/langchain/langchain_classic/chains/qa_with_sources/retrieval.py:65-70 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:415— libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:415-420 | libs/langchain/langchain_classic/chains/qa_with_sources/retrieval.py:52-57 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (21 lines × 2) libs/core/langchain_core/runnables/base.py:3533— libs/core/langchain_core/runnables/base.py:3533-3553 | libs/core/langchain_core/runnables/fallbacks.py:282-302 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3533` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (21 lines × 2) libs/core/langchain_core/tracers/event_stream.py:199— libs/core/langchain_core/tracers/event_stream.py:199-219 | libs/core/langchain_core/tracers/event_stream.py:249-269 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (21 lines × 2) libs/langchain/langchain_classic/agents/chat/output_parser.py:40— libs/langchain/langchain_classic/agents/chat/output_parser.py:40-60 | libs/langchain/langchain_classic/agents/output_parsers/react_json_single_input.py:55-75 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (21 lines × 2) libs/core/langchain_core/language_models/llms.py:438— libs/core/langchain_core/language_models/llms.py:438-458 | libs/core/langchain_core/language_models/llms.py:484-504 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/llms.py:438` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (21 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:783— libs/partners/qdrant/langchain_qdrant/qdrant.py:783-803 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:865-915 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (18 lines × 3) libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:142— libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:142-161 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:209-226 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:240-257 — `libs/langchain/langchain_classic/agents/openai_functions_agent/base.py` and `libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 75 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (18 lines × 3) libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:104— libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:104-121 | libs/langchain/langchain_classic/chains/question_answering/chain.py:144-161 | libs/langchain/langchain_classic/chains/summarize/chain.py:132-149 — before extracting anything, compare `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py` and `libs/langchain/langchain_classic/chains/summarize/chain.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 46 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:104` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18 lines × 3) REDACTED:450— REDACTED:450-469 | libs/partners/groq/langchain_groq/chat_models.py:1445-1462 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:165-182 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:450` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (18 lines × 3) REDACTED:1976— REDACTED:1976-1993 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1161-1178 | libs/partners/ollama/langchain_ollama/chat_models.py:1700-1717 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (18 lines × 3) libs/partners/ollama/langchain_ollama/chat_models.py:951— libs/partners/ollama/langchain_ollama/chat_models.py:951-968 | libs/partners/ollama/langchain_ollama/embeddings.py:297-314 | libs/partners/ollama/langchain_ollama/llms.py:331-348 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (7 lines × 3) libs/core/langchain_core/language_models/_compat_bridge.py:313— libs/core/langchain_core/language_models/_compat_bridge.py:313-319 | libs/core/langchain_core/language_models/_compat_bridge.py:326-332 | libs/core/langchain_core/language_models/_compat_bridge.py:341-347 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 3) libs/partners/groq/langchain_groq/chat_models.py:1543— libs/partners/groq/langchain_groq/chat_models.py:1543-1549 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:195-201 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1361-1367 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/partners/groq/langchain_groq/chat_models.py:1542` calls `get` and `libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:192` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (7 lines × 3) libs/partners/qdrant/langchain_qdrant/qdrant.py:1045— libs/partners/qdrant/langchain_qdrant/qdrant.py:1045-1051 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2204-2210 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2245-2251 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
Duplicated block (7 lines × 3) libs/partners/openai/langchain_openai/chat_models/azure.py:890— libs/partners/openai/langchain_openai/chat_models/azure.py:890-896 | libs/partners/openai/langchain_openai/chat_models/base.py:3874-3880 | libs/partners/xai/langchain_xai/chat_models.py:632-638 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (7 lines × 3) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:870— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:870-876 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:888-894 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:907-915 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (6 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:731— libs/langchain/langchain_classic/chat_models/base.py:731-738 | libs/langchain_v1/langchain/chat_models/base.py:726-731 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chat_models/base.py:731` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (6 lines × 2) libs/model-profiles/langchain_model_profiles/cli.py:78— libs/model-profiles/langchain_model_profiles/cli.py:78-83 | libs/model-profiles/langchain_model_profiles/cli.py:340-345 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) libs/partners/anthropic/langchain_anthropic/_compat.py:28— libs/partners/anthropic/langchain_anthropic/_compat.py:28-33 | libs/partners/anthropic/langchain_anthropic/_compat.py:73-78 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/partners/anthropic/langchain_anthropic/_compat.py:35` calls `get` and `libs/partners/anthropic/langchain_anthropic/_compat.py:80` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (6 lines × 2) libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:20— libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:20-25 | libs/langchain/langchain_classic/callbacks/streaming_stdout_final_only.py:21-26 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (6 lines × 2) libs/partners/openai/langchain_openai/decisions/base.py:223— libs/partners/openai/langchain_openai/decisions/base.py:223-228 | libs/partners/openai/langchain_openai/decisions/classifier.py:244-249 — before extracting anything, compare `libs/partners/openai/langchain_openai/decisions/base.py` and `libs/partners/openai/langchain_openai/decisions/classifier.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 37 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Low cohesion: ChatXAI (LCOM4 10) libs/partners/xai/langchain_xai/chat_models.py:61— ChatXAI's methods fall into 10 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 10 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: ChatDeepSeek (LCOM4 8) libs/partners/deepseek/langchain_deepseek/chat_models.py:110— ChatDeepSeek's methods fall into 8 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 8 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: VectorStore (LCOM4 6) libs/core/langchain_core/vectorstores/base.py:44— VectorStore's methods fall into 6 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 6 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: BaseTool (LCOM4 5) libs/core/langchain_core/tools/base.py:434— BaseTool's methods fall into 5 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 5 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: ChatModelUnitTests (LCOM4 5) libs/standard-tests/langchain_tests/unit_tests/chat_models.py:277— ChatModelUnitTests's methods fall into 5 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 5 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Change coupling: extraction.py ↔ REDACTED libs/langchain/langchain_classic/chains/openai_tools/extraction.py:1— `libs/langchain/langchain_classic/chains/openai_tools/extraction.py` and `libs/langchain/langchain_classic/chains/structured_output/base.py` change together 80% of the time (8 of the 10 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well, and counted over this repository's 10,000 most recent commits rather than its whole history — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 8 shared commits counted here, the most recent 3 are `468dad17` chore: use model IDs, latest anthropic models (#33747); `09102a63` fix: update some links (#33686); `6e25e185` fix(docs): Fix several typos and grammar (#33487) — run `git show` on any of them.
Change coupling: context_editing.py ↔ todo.py libs/langchain_v1/langchain/agents/middleware/context_editing.py:1— `libs/langchain_v1/langchain/agents/middleware/context_editing.py` and `libs/langchain_v1/langchain/agents/middleware/todo.py` change together 75% of the time (9 of the 12 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well, and counted over this repository's 10,000 most recent commits rather than its whole history — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency between them. They sit in the same directory, but in this ecosystem each file is its own module — a sibling reference still needs an import — so the missing import edge is real: the coupling runs through shared behaviour, not a declared dependency. If they duplicate structure, extract the common part into one unit; otherwise the coupling is hidden and worth breaking. You can check this without leaving the row: of the 9 shared commits counted here, the most recent 3 are `4ab94579` feat(langchain): support `SystemMessage` in `create_agent`'s `system_…; `b7d1831f` fix: deprecate `setattr` on `ModelCallRequest` (#34022); `f2410f7e` revert: Support for SystemMessage in create_agent (#33889) — run `git show` on any of them.
Change coupling: extraction.py ↔ extraction.py libs/langchain/langchain_classic/chains/openai_functions/extraction.py:1— `libs/langchain/langchain_classic/chains/openai_functions/extraction.py` and `libs/langchain/langchain_classic/chains/openai_tools/extraction.py` change together 70% of the time (7 of the 10 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well, and counted over this repository's 10,000 most recent commits rather than its whole history — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 7 shared commits counted here, the most recent 3 are `468dad17` chore: use model IDs, latest anthropic models (#33747); `09102a63` fix: update some links (#33686); `6e25e185` fix(docs): Fix several typos and grammar (#33487) — run `git show` on any of them.
Change coupling: factory.py ↔ context_editing.py libs/langchain_v1/langchain/agents/factory.py:1— `libs/langchain_v1/langchain/agents/factory.py` and `libs/langchain_v1/langchain/agents/middleware/context_editing.py` change together 58% of the time (7 of the 12 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well, and counted over this repository's 10,000 most recent commits rather than its whole history — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 7 shared commits counted here, the most recent 3 are `4ab94579` feat(langchain): support `SystemMessage` in `create_agent`'s `system_…; `f2410f7e` revert: Support for SystemMessage in create_agent (#33889); `cf595dcc` chore(langchain): Support for SystemMessage in create_agent (#33640) — run `git show` on any of them.
D4 · Code Duplication· Edited copy of a member (14 corresponding lines) · ×4
Edited copy of a member (14 corresponding lines) libs/core/langchain_core/tracers/base.py:46— libs/core/langchain_core/tracers/base.py:46-59 | libs/core/langchain_core/tracers/base.py:572-589 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:675— libs/langchain/langchain_classic/chat_models/base.py:675-688 | libs/langchain_v1/langchain/chat_models/base.py:670-683 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:803— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:803-816 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:870-883 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:422— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:422-435 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:506-519 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (8 corresponding lines) · ×4
Edited copy of a member (8 corresponding lines) libs/partners/openai/langchain_openai/decisions/_input.py:132— libs/partners/openai/langchain_openai/decisions/_input.py:132-140 | libs/partners/openai/langchain_openai/middleware/model_router.py:260-267 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (8 corresponding lines) libs/langchain/langchain_classic/retrievers/self_query/base.py:316— libs/langchain/langchain_classic/retrievers/self_query/base.py:316-323 | libs/langchain/langchain_classic/retrievers/self_query/base.py:332-339 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (8 corresponding lines) libs/langchain/langchain_classic/chains/llm_math/base.py:273— libs/langchain/langchain_classic/chains/llm_math/base.py:273-280 | libs/langchain/langchain_classic/chains/llm_math/base.py:287-294 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (8 corresponding lines) libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:65— libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:65-83 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:128-135 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (9 corresponding lines) · ×4
Edited copy of a member (9 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:728— libs/langchain/langchain_classic/chat_models/base.py:728-738 | libs/langchain_v1/langchain/chat_models/base.py:723-731 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) libs/core/langchain_core/runnables/base.py:4556— libs/core/langchain_core/runnables/base.py:4556-4564 | libs/core/langchain_core/runnables/base.py:4981-4990 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) libs/langchain/langchain_classic/agents/conversational_chat/base.py:124— libs/langchain/langchain_classic/agents/conversational_chat/base.py:124-132 | libs/langchain/langchain_classic/agents/format_scratchpad/log_to_messages.py:9-26 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/chain_extract.py:118— libs/langchain/langchain_classic/retrievers/document_compressors/chain_extract.py:118-126 | libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:119-135 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (7 corresponding lines) · ×4
Edited copy of a member (7 corresponding lines) libs/langchain/langchain_classic/chains/sequential.py:96— libs/langchain/langchain_classic/chains/sequential.py:96-102 | libs/langchain/langchain_classic/chains/sequential.py:109-119 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) libs/core/langchain_core/language_models/fake.py:51— libs/core/langchain_core/language_models/fake.py:51-57 | libs/core/langchain_core/language_models/fake_chat_models.py:81-92 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/base_store.py:111— libs/standard-tests/langchain_tests/integration_tests/base_store.py:111-117 | libs/standard-tests/langchain_tests/integration_tests/base_store.py:257-263 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/base_store.py:227— libs/standard-tests/langchain_tests/integration_tests/base_store.py:227-233 | libs/standard-tests/langchain_tests/integration_tests/base_store.py:287-297 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (20 corresponding lines) · ×4
Edited copy of a member (20 corresponding lines) libs/langchain_v1/langchain/agents/middleware/context_editing.py:255— libs/langchain_v1/langchain/agents/middleware/context_editing.py:255-274 | libs/langchain_v1/langchain/agents/middleware/context_editing.py:281-300 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (20 corresponding lines) libs/core/langchain_core/load/_validation.py:166— libs/core/langchain_core/load/_validation.py:166-191 | libs/partners/typesafe/langchain_typesafe/_assets.py:27-46 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (20 corresponding lines) libs/core/langchain_core/callbacks/base.py:1018— libs/core/langchain_core/callbacks/base.py:1018-1037 | libs/core/langchain_core/callbacks/manager.py:492-512 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (20 corresponding lines) libs/langchain_v1/examples/mcp/remote_server.py:21— libs/langchain_v1/examples/mcp/remote_server.py:21-40 | libs/langchain_v1/examples/mcp/tool_errors.py:22-41 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (32 lines × 2) libs/core/langchain_core/tools/base.py:1100— libs/core/langchain_core/tools/base.py:1100-1131 | libs/core/langchain_core/tools/base.py:1230-1261 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (32 lines × 2) libs/langchain/langchain_classic/agents/agent.py:1318— libs/langchain/langchain_classic/agents/agent.py:1318-1349 | libs/langchain/langchain_classic/agents/agent.py:1457-1488 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/agent.py:1318` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (32 lines × 2) libs/langchain/langchain_classic/agents/mrkl/output_parser.py:64— libs/langchain/langchain_classic/agents/mrkl/output_parser.py:64-95 | libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py:64-95 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/langchain/langchain_classic/agents/mrkl/output_parser.py:63` calls `startswith` and `libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py:63` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (32 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1039— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1039-1070 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1117-1148 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/qdrant/langchain_qdrant/vectorstores.py:1039` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (29 lines × 2) libs/core/langchain_core/language_models/chat_models.py:787— libs/core/langchain_core/language_models/chat_models.py:787-815 | libs/core/langchain_core/language_models/chat_models.py:1059-1087 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/core/langchain_core/language_models/chat_models.py:1052` calls `_normalize_messages` and `libs/core/langchain_core/language_models/chat_models.py:786` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (29 lines × 2) libs/core/langchain_core/language_models/chat_models.py:920— libs/core/langchain_core/language_models/chat_models.py:920-948 | libs/core/langchain_core/language_models/chat_models.py:1197-1225 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/core/langchain_core/language_models/chat_models.py:1193` calls `_normalize_messages` and `libs/core/langchain_core/language_models/chat_models.py:918` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (29 lines × 2) libs/core/langchain_core/language_models/chat_models.py:1581— libs/core/langchain_core/language_models/chat_models.py:1581-1609 | libs/core/langchain_core/language_models/llms.py:343-371 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (29 lines × 2) libs/langchain/langchain_classic/agents/agent.py:425— libs/langchain/langchain_classic/agents/agent.py:425-453 | libs/langchain/langchain_classic/agents/agent.py:537-565 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (27 lines × 2) libs/core/langchain_core/callbacks/manager.py:1390— libs/core/langchain_core/callbacks/manager.py:1390-1416 | libs/core/langchain_core/callbacks/manager.py:1444-1470 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (27 lines × 2) libs/core/langchain_core/runnables/utils.py:474— libs/core/langchain_core/runnables/utils.py:474-500 | libs/core/langchain_core/runnables/utils.py:503-529 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (27 lines × 2) libs/core/langchain_core/_api/__init__.py:61— libs/core/langchain_core/_api/__init__.py:61-87 | libs/core/langchain_core/vectorstores/__init__.py:27-53 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (27 lines × 2) libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:257— libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:257-283 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:310-336 — `libs/langchain/langchain_classic/agents/openai_functions_agent/base.py` and `libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 75 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (22–24 lines × 2) libs/core/langchain_core/callbacks/manager.py:1917— libs/core/langchain_core/callbacks/manager.py:1917-1940 | libs/core/langchain_core/callbacks/manager.py:1990-2011 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/callbacks/manager.py:1917` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (22–24 lines × 2) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1539— libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1539-1562 | libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1716-1737 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note first that the copies are not typed on the same thing: `Client` names `langsmith` in one and `langsmith.client` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (22–24 lines × 2) libs/langchain_v1/langchain/agents/middleware/types.py:1994— libs/langchain_v1/langchain/agents/middleware/types.py:1994-2017 | libs/langchain_v1/langchain/agents/middleware/types.py:2182-2203 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note first that the copies are not typed on the same thing: the declarations holding them bind `handler` to `Callable[[ModelRequest[ContextT]], ModelResponse[ResponseT]]` in one and `Callable[[ToolCallRequest], ToolMessage | Command[Any]]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (22–24 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:1255— libs/partners/groq/langchain_groq/chat_models.py:1255-1278 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1000-1021 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/groq/langchain_groq/chat_models.py:1255` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (22 lines × 4) libs/langchain/langchain_classic/chains/loading.py:433— libs/langchain/langchain_classic/chains/loading.py:433-454 | libs/langchain/langchain_classic/chains/loading.py:463-484 | libs/langchain/langchain_classic/chains/loading.py:496-517 | libs/langchain/langchain_classic/chains/loading.py:526-547 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (22 lines × 4) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:294— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:294-315 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:324-345 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:788-809 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:818-839 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (22 lines × 4) libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:445— libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:445-467 | libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:599-621 | libs/langchain/langchain_classic/evaluation/string_distance/base.py:262-285 | libs/langchain/langchain_classic/evaluation/string_distance/base.py:396-417 — there are 4 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (22 lines × 4) libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:481— libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:481-503 | libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:635-657 | libs/langchain/langchain_classic/evaluation/string_distance/base.py:300-322 | libs/langchain/langchain_classic/evaluation/string_distance/base.py:431-452 — there are 4 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (14–15 lines × 2) libs/core/langchain_core/indexing/api.py:513— libs/core/langchain_core/indexing/api.py:513-527 | libs/core/langchain_core/indexing/api.py:863-876 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14–15 lines × 2) libs/core/langchain_core/messages/block_translators/openai.py:809— libs/core/langchain_core/messages/block_translators/openai.py:809-823 | libs/core/langchain_core/messages/block_translators/openai.py:850-863 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14–15 lines × 2) libs/core/langchain_core/runnables/base.py:5191— libs/core/langchain_core/runnables/base.py:5191-5204 | libs/core/langchain_core/runnables/base.py:5386-5400 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14–15 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2351— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2351-2364 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2433-2447 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2351` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–11 lines × 2) libs/core/langchain_core/language_models/chat_model_stream.py:776— libs/core/langchain_core/language_models/chat_model_stream.py:776-785 | libs/core/langchain_core/language_models/chat_model_stream.py:822-832 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_model_stream.py:776` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10–11 lines × 2) libs/core/langchain_core/tracers/base.py:48— libs/core/langchain_core/tracers/base.py:48-58 | libs/core/langchain_core/tracers/base.py:579-588 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10–11 lines × 2) libs/partners/mistralai/langchain_mistralai/chat_models.py:911— libs/partners/mistralai/langchain_mistralai/chat_models.py:911-921 | libs/partners/mistralai/langchain_mistralai/chat_models.py:942-951 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/mistralai/langchain_mistralai/chat_models.py:911` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10–11 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:893— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:893-902 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:913-923 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:913` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 2) libs/core/langchain_core/tools/simple.py:51— libs/core/langchain_core/tools/simple.py:51-55 | libs/core/langchain_core/tools/structured.py:121-125 — before extracting anything, compare `libs/core/langchain_core/tools/simple.py` and `libs/core/langchain_core/tools/structured.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (5 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:721— libs/langchain/langchain_classic/chat_models/base.py:721-725 | libs/langchain_v1/langchain/chat_models/base.py:716-720 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (5 lines × 2) libs/langchain/langchain_classic/agents/output_parsers/openai_tools.py:62— libs/langchain/langchain_classic/agents/output_parsers/openai_tools.py:62-66 | libs/langchain/langchain_classic/agents/output_parsers/tools.py:107-111 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (5 lines × 2) libs/standard-tests/langchain_tests/integration_tests/embeddings.py:74— libs/standard-tests/langchain_tests/integration_tests/embeddings.py:74-78 | libs/standard-tests/langchain_tests/integration_tests/embeddings.py:115-119 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Swallowed exception (empty catch) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:371— An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch.
Swallowed exception (empty catch) libs/partners/openai/langchain_openai/chat_models/_client_utils.py:384— An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch.
Swallowed exception (empty catch) libs/partners/anthropic/langchain_anthropic/_client_utils.py:29— An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch.
Swallowed exception (empty catch) libs/partners/anthropic/langchain_anthropic/_client_utils.py:42— An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch.
D4 · Code Duplication· Edited copy of a member (61 corresponding lines) · ×3
Edited copy of a member (61 corresponding lines) libs/partners/openai/langchain_openai/embeddings/base.py:584— libs/partners/openai/langchain_openai/embeddings/base.py:584-644 | libs/partners/openai/langchain_openai/embeddings/base.py:656-722 — These two members are one piece of code written twice and then edited apart: 61 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (61 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py:1710— libs/partners/openai/langchain_openai/chat_models/base.py:1710-1770 | libs/partners/openai/langchain_openai/chat_models/base.py:1779-1846 — These two members are one piece of code written twice and then edited apart: 61 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (61 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2452— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2452-2521 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2599-2659 — These two members are one piece of code written twice and then edited apart: 61 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (48 corresponding lines) · ×3
Edited copy of a member (48 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py:719— libs/partners/groq/langchain_groq/chat_models.py:719-766 | libs/partners/groq/langchain_groq/chat_models.py:775-824 — These two members are one piece of code written twice and then edited apart: 48 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (48 corresponding lines) libs/langchain/langchain_classic/agents/agent.py:1575— libs/langchain/langchain_classic/agents/agent.py:1575-1622 | libs/langchain/langchain_classic/agents/agent.py:1629-1695 — These two members are one piece of code written twice and then edited apart: 48 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (48 corresponding lines) libs/core/langchain_core/tracers/event_stream.py:182— libs/core/langchain_core/tracers/event_stream.py:182-232 | libs/core/langchain_core/tracers/event_stream.py:235-282 — These two members are one piece of code written twice and then edited apart: 48 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (42 corresponding lines) · ×3
Edited copy of a member (42 corresponding lines) libs/langchain/langchain_classic/agents/mrkl/output_parser.py:32— libs/langchain/langchain_classic/agents/mrkl/output_parser.py:32-95 | libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py:54-95 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (42 corresponding lines) libs/core/langchain_core/prompts/few_shot_with_templates.py:125— libs/core/langchain_core/prompts/few_shot_with_templates.py:125-169 | libs/core/langchain_core/prompts/few_shot_with_templates.py:172-213 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (42 corresponding lines) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:55— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:55-96 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:56-97 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (43 corresponding lines) · ×3
Edited copy of a member (43 corresponding lines) libs/core/langchain_core/runnables/branch.py:188— libs/core/langchain_core/runnables/branch.py:188-241 | libs/core/langchain_core/runnables/branch.py:247-289 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (43 corresponding lines) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:438— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:438-483 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:488-530 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (43 corresponding lines) libs/core/langchain_core/vectorstores/base.py:513— libs/core/langchain_core/vectorstores/base.py:513-555 | libs/core/langchain_core/vectorstores/base.py:563-605 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (40 corresponding lines) · ×3
Edited copy of a member (40 corresponding lines) libs/partners/anthropic/langchain_anthropic/chat_models.py:2215— libs/partners/anthropic/langchain_anthropic/chat_models.py:2215-2254 | libs/partners/anthropic/langchain_anthropic/chat_models.py:2265-2304 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (40 corresponding lines) libs/core/langchain_core/vectorstores/base.py:55— libs/core/langchain_core/vectorstores/base.py:55-98 | libs/core/langchain_core/vectorstores/base.py:194-233 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (40 corresponding lines) libs/langchain/langchain_classic/chains/query_constructor/base.py:284— libs/langchain/langchain_classic/chains/query_constructor/base.py:284-323 | libs/langchain/langchain_classic/chains/query_constructor/base.py:339-381 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (38 corresponding lines) · ×3
Edited copy of a member (38 corresponding lines) libs/core/langchain_core/runnables/base.py:4279— libs/core/langchain_core/runnables/base.py:4279-4316 | libs/core/langchain_core/runnables/base.py:4345-4386 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (38 corresponding lines) libs/partners/anthropic/langchain_anthropic/llms.py:333— libs/partners/anthropic/langchain_anthropic/llms.py:333-370 | libs/partners/anthropic/langchain_anthropic/llms.py:379-416 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (38 corresponding lines) libs/partners/qdrant/langchain_qdrant/qdrant.py:656— libs/partners/qdrant/langchain_qdrant/qdrant.py:656-697 | libs/partners/qdrant/langchain_qdrant/qdrant.py:817-854 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (21 corresponding lines) · ×3
Edited copy of a member (21 corresponding lines) libs/langchain/langchain_classic/chains/llm.py:125— libs/langchain/langchain_classic/chains/llm.py:125-145 | libs/langchain/langchain_classic/chains/llm.py:152-172 — These two members are one piece of code written twice and then edited apart: 21 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (21 corresponding lines) libs/langchain/langchain_classic/chains/qa_with_sources/base.py:158— libs/langchain/langchain_classic/chains/qa_with_sources/base.py:158-179 | libs/langchain/langchain_classic/chains/qa_with_sources/base.py:195-215 — These two members are one piece of code written twice and then edited apart: 21 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (21 corresponding lines) libs/langchain/langchain_classic/chains/combine_documents/refine.py:151— libs/langchain/langchain_classic/chains/combine_documents/refine.py:151-171 | libs/langchain/langchain_classic/chains/combine_documents/refine.py:179-199 — These two members are one piece of code written twice and then edited apart: 21 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 10+ corresponding lines) · ×3
Edited copies of one member (3 members, 10+ corresponding lines) libs/core/langchain_core/callbacks/base.py:1040— libs/core/langchain_core/callbacks/base.py:1040-1049 | libs/core/langchain_core/callbacks/manager.py:1748-1757 | libs/core/langchain_core/callbacks/manager.py:2275-2285 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 10 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Edited copies of one member (3 members, 10+ corresponding lines) libs/langchain/langchain_classic/memory/summary_buffer.py:116— libs/langchain/langchain_classic/memory/summary_buffer.py:116-127 | libs/langchain/langchain_classic/memory/summary_buffer.py:130-141 | libs/langchain/langchain_classic/memory/token_buffer.py:65-74 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 10 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Edited copies of one member (3 members, 10+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:133— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:133-142 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:380-396 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:680-694 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 10 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Duplicated block (34–35 lines × 2) libs/langchain/langchain_classic/agents/agent.py:461— libs/langchain/langchain_classic/agents/agent.py:461-494 | libs/langchain/langchain_classic/agents/agent.py:573-607 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (34–35 lines × 2) libs/langchain/langchain_classic/output_parsers/retry.py:133— libs/langchain/langchain_classic/output_parsers/retry.py:133-166 | libs/langchain/langchain_classic/output_parsers/retry.py:263-297 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (34–35 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:728— libs/partners/groq/langchain_groq/chat_models.py:728-762 | libs/partners/groq/langchain_groq/chat_models.py:785-818 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (33 lines × 2) libs/core/langchain_core/indexing/api.py:472— libs/core/langchain_core/indexing/api.py:472-504 | libs/core/langchain_core/indexing/api.py:822-854 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (33 lines × 2) libs/core/langchain_core/messages/block_translators/anthropic.py:304— libs/core/langchain_core/messages/block_translators/anthropic.py:304-336 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:228-260 — before extracting anything, compare `libs/core/langchain_core/messages/block_translators/anthropic.py` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/core/langchain_core/messages/block_translators/anthropic.py:302` calls `setdefault` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py:227` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (33 lines × 2) libs/core/langchain_core/output_parsers/openai_tools.py:167— libs/core/langchain_core/output_parsers/openai_tools.py:167-199 | libs/core/langchain_core/output_parsers/openai_tools.py:234-266 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (30 lines × 2) libs/core/langchain_core/language_models/chat_models.py:2325— libs/core/langchain_core/language_models/chat_models.py:2325-2354 | libs/core/langchain_core/language_models/llms.py:752-790 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (30 lines × 2) libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:55— libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:55-84 | libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py:56-85 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py:55` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (30 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1339— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1339-1368 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1580-1609 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (25 lines × 2) libs/core/langchain_core/messages/block_translators/anthropic.py:275— libs/core/langchain_core/messages/block_translators/anthropic.py:275-299 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:203-227 — before extracting anything, compare `libs/core/langchain_core/messages/block_translators/anthropic.py` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/messages/block_translators/anthropic.py:302` calls `setdefault` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py:228` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (25 lines × 2) libs/core/langchain_core/vectorstores/base.py:531— libs/core/langchain_core/vectorstores/base.py:531-555 | libs/core/langchain_core/vectorstores/base.py:581-605 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/vectorstores/base.py:531` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (25 lines × 2) libs/langchain_v1/langchain/agents/middleware/summarization.py:482— libs/langchain_v1/langchain/agents/middleware/summarization.py:482-506 | libs/langchain_v1/langchain/agents/middleware/summarization.py:523-547 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23 lines × 2) libs/core/langchain_core/tools/simple.py:133— libs/core/langchain_core/tools/simple.py:133-155 | libs/core/langchain_core/tools/structured.py:163-185 — before extracting anything, compare `libs/core/langchain_core/tools/simple.py` and `libs/core/langchain_core/tools/structured.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23 lines × 2) libs/langchain_v1/langchain/agents/middleware/file_search.py:406— libs/langchain_v1/langchain/agents/middleware/file_search.py:406-428 | libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:333-355 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/file_search.py` and `libs/partners/anthropic/langchain_anthropic/middleware/file_search.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 55 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23 lines × 2) libs/langchain_v1/langchain/agents/middleware/tool_selection.py:417— libs/langchain_v1/langchain/agents/middleware/tool_selection.py:417-439 | libs/langchain_v1/langchain/agents/middleware/tool_selection.py:485-507 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (22–23 lines × 2) libs/langchain/langchain_classic/_api/module_import.py:95— libs/langchain/langchain_classic/_api/module_import.py:95-116 | libs/langchain/langchain_classic/_api/module_import.py:129-151 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/_api/module_import.py:95` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (22–23 lines × 2) libs/langchain_v1/langchain/agents/middleware/types.py:1776— libs/langchain_v1/langchain/agents/middleware/types.py:1776-1797 | libs/langchain_v1/langchain/agents/middleware/types.py:1818-1840 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (22–23 lines × 2) libs/partners/openai/langchain_openai/embeddings/base.py:601— libs/partners/openai/langchain_openai/embeddings/base.py:601-622 | libs/partners/openai/langchain_openai/embeddings/base.py:674-696 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openai/langchain_openai/embeddings/base.py:674` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (22 lines × 2) libs/langchain/langchain_classic/agents/agent.py:1738— libs/langchain/langchain_classic/agents/agent.py:1738-1759 | libs/langchain/langchain_classic/agents/agent.py:1769-1790 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (22 lines × 2) libs/langchain_v1/langchain/agents/middleware/shell_tool.py:277— libs/langchain_v1/langchain/agents/middleware/shell_tool.py:277-298 | libs/langchain_v1/langchain/agents/middleware/shell_tool.py:362-383 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (22 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:2215— libs/partners/qdrant/langchain_qdrant/vectorstores.py:2215-2236 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2256-2277 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–14 lines × 2) libs/core/langchain_core/prompts/few_shot_with_templates.py:142— libs/core/langchain_core/prompts/few_shot_with_templates.py:142-153 | libs/core/langchain_core/prompts/few_shot_with_templates.py:184-197 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–14 lines × 2) libs/partners/openrouter/langchain_openrouter/chat_models.py:608— libs/partners/openrouter/langchain_openrouter/chat_models.py:608-619 | libs/partners/openrouter/langchain_openrouter/chat_models.py:698-711 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openrouter/langchain_openrouter/chat_models.py:698` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12–14 lines × 2) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1356— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1356-1369 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1563-1574 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–13 lines × 2) libs/core/langchain_core/tracers/event_stream.py:934— libs/core/langchain_core/tracers/event_stream.py:934-946 | libs/core/langchain_core/tracers/event_stream.py:962-973 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–13 lines × 2) libs/langchain/langchain_classic/chains/loading.py:76— libs/langchain/langchain_classic/chains/loading.py:76-87 | libs/langchain/langchain_classic/chains/loading.py:322-334 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–13 lines × 2) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:463— libs/langchain/langchain_classic/indexes/_sql_record_manager.py:463-474 | libs/langchain/langchain_classic/indexes/_sql_record_manager.py:490-502 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/indexes/_sql_record_manager.py:463` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 3) libs/langchain/langchain_classic/agents/json_chat/base.py:173— libs/langchain/langchain_classic/agents/json_chat/base.py:173-183 | libs/langchain/langchain_classic/agents/react/agent.py:131-141 | libs/langchain/langchain_classic/agents/structured_chat/base.py:298-308 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (11 lines × 3) libs/langchain/langchain_classic/output_parsers/fix.py:109— libs/langchain/langchain_classic/output_parsers/fix.py:109-119 | libs/langchain/langchain_classic/output_parsers/retry.py:142-152 | libs/langchain/langchain_classic/output_parsers/retry.py:272-282 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/output_parsers/fix.py:109` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 3) libs/partners/groq/langchain_groq/chat_models.py:510— libs/partners/groq/langchain_groq/chat_models.py:510-520 | libs/partners/openai/langchain_openai/embeddings/base.py:350-360 | libs/partners/openrouter/langchain_openrouter/chat_models.py:381-391 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/groq/langchain_groq/chat_models.py:510` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–11 lines × 2) libs/core/langchain_core/language_models/chat_models.py:529— libs/core/langchain_core/language_models/chat_models.py:529-537 | libs/core/langchain_core/language_models/llms.py:384-394 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_models.py:529` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9–11 lines × 2) REDACTED:1702— REDACTED:1702-1710 | REDACTED:1712-1722 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1702` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9–11 lines × 2) libs/core/langchain_core/tracers/core.py:529— libs/core/langchain_core/tracers/core.py:529-537 | libs/core/langchain_core/tracers/core.py:585-595 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
chat_models._convert_chunk_to_message_chunk (cognitive 30) REDACTED:545— chat_models._convert_chunk_to_message_chunk has cognitive complexity 30 (threshold 15). Drivers by points: if/else 12 (14 pts), boolean chains 10, ternaries 2 (4 pts), loops 1 (2 pts) (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
chat_models._convert_chunk_to_message_chunk (cognitive 30) libs/partners/openrouter/langchain_openrouter/chat_models.py:1414— chat_models._convert_chunk_to_message_chunk has cognitive complexity 30 (threshold 15). Drivers by points: if/else 12 (19 pts), boolean chains 6, error handling 1 (3 pts), loops 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
D4 · Code Duplication· Edited copy of a member (71 corresponding lines) · ×2
Edited copy of a member (71 corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py:595— libs/langchain/langchain_classic/agents/openai_assistant/base.py:595-669 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:752-822 — These two members are one piece of code written twice and then edited apart: 71 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (71 corresponding lines) libs/core/langchain_core/language_models/_compat_bridge.py:592— libs/core/langchain_core/language_models/_compat_bridge.py:592-689 | libs/core/langchain_core/language_models/_compat_bridge.py:698-768 — These two members are one piece of code written twice and then edited apart: 71 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (67 corresponding lines) · ×2
Edited copy of a member (67 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py:1876— libs/partners/openai/langchain_openai/chat_models/base.py:1876-1942 | libs/partners/openai/langchain_openai/chat_models/base.py:2172-2243 — These two members are one piece of code written twice and then edited apart: 67 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (67 corresponding lines) libs/core/langchain_core/runnables/base.py:2570— libs/core/langchain_core/runnables/base.py:2570-2636 | libs/core/langchain_core/runnables/base.py:2654-2724 — These two members are one piece of code written twice and then edited apart: 67 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (51 corresponding lines) · ×2
Edited copy of a member (51 corresponding lines) REDACTED:548— REDACTED:548-612 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:253-303 — These two members are one piece of code written twice and then edited apart: 51 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (51 corresponding lines) libs/partners/openai/langchain_openai/llms/base.py:453— libs/partners/openai/langchain_openai/llms/base.py:453-528 | libs/partners/openai/langchain_openai/llms/base.py:537-587 — These two members are one piece of code written twice and then edited apart: 51 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (64 corresponding lines) · ×2
Edited copy of a member (64 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py:1951— libs/partners/openai/langchain_openai/chat_models/base.py:1951-2014 | libs/partners/openai/langchain_openai/chat_models/base.py:2252-2320 — These two members are one piece of code written twice and then edited apart: 64 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (64 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:996— libs/partners/qdrant/langchain_qdrant/vectorstores.py:996-1070 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1085-1148 — These two members are one piece of code written twice and then edited apart: 64 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (73 corresponding lines) · ×2
Edited copy of a member (73 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py:1376— libs/partners/groq/langchain_groq/chat_models.py:1376-1462 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1272-1344 — These two members are one piece of code written twice and then edited apart: 73 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (73 corresponding lines) libs/partners/openai/langchain_openai/embeddings/azure.py:163— libs/partners/openai/langchain_openai/embeddings/azure.py:163-235 | libs/partners/openai/langchain_openai/llms/azure.py:128-212 — These two members are one piece of code written twice and then edited apart: 73 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (60 corresponding lines) · ×2
Edited copy of a member (60 corresponding lines) libs/core/langchain_core/language_models/llms.py:522— libs/core/langchain_core/language_models/llms.py:522-581 | libs/core/langchain_core/language_models/llms.py:592-655 — These two members are one piece of code written twice and then edited apart: 60 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (60 corresponding lines) libs/core/langchain_core/messages/ai.py:244— libs/core/langchain_core/messages/ai.py:244-304 | libs/core/langchain_core/messages/ai.py:447-506 — These two members are one piece of code written twice and then edited apart: 60 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (70 corresponding lines) · ×2
Edited copy of a member (70 corresponding lines) libs/langchain/langchain_classic/agents/agent.py:1309— libs/langchain/langchain_classic/agents/agent.py:1309-1378 | libs/langchain/langchain_classic/agents/agent.py:1448-1525 — These two members are one piece of code written twice and then edited apart: 70 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (70 corresponding lines) libs/core/langchain_core/callbacks/manager.py:69— libs/core/langchain_core/callbacks/manager.py:69-138 | libs/core/langchain_core/callbacks/manager.py:154-226 — These two members are one piece of code written twice and then edited apart: 70 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (54 corresponding lines) · ×2
Edited copy of a member (54 corresponding lines) libs/core/langchain_core/runnables/retry.py:241— libs/core/langchain_core/runnables/retry.py:241-295 | libs/core/langchain_core/runnables/retry.py:317-370 — These two members are one piece of code written twice and then edited apart: 54 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (54 corresponding lines) libs/partners/groq/langchain_groq/chat_models.py:1623— libs/partners/groq/langchain_groq/chat_models.py:1623-1676 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1526-1581 — These two members are one piece of code written twice and then edited apart: 54 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (62 corresponding lines) · ×2
Edited copy of a member (62 corresponding lines) libs/langchain/langchain_classic/agents/agent_iterator.py:173— libs/langchain/langchain_classic/agents/agent_iterator.py:173-234 | libs/langchain/langchain_classic/agents/agent_iterator.py:237-315 — These two members are one piece of code written twice and then edited apart: 62 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (62 corresponding lines) libs/langchain_v1/langchain/agents/middleware/tool_selection.py:379— libs/langchain_v1/langchain/agents/middleware/tool_selection.py:379-440 | libs/langchain_v1/langchain/agents/middleware/tool_selection.py:447-508 — These two members are one piece of code written twice and then edited apart: 62 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (44 corresponding lines) · ×2
Edited copy of a member (44 corresponding lines) libs/core/langchain_core/_security/_transport.py:62— libs/core/langchain_core/_security/_transport.py:62-115 | libs/core/langchain_core/_security/_transport.py:148-191 — These two members are one piece of code written twice and then edited apart: 44 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (44 corresponding lines) libs/core/langchain_core/utils/utils.py:375— libs/core/langchain_core/utils/utils.py:375-421 | libs/core/langchain_core/utils/utils.py:449-492 — These two members are one piece of code written twice and then edited apart: 44 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (49 corresponding lines) · ×2
Edited copy of a member (49 corresponding lines) libs/core/langchain_core/runnables/base.py:2432— libs/core/langchain_core/runnables/base.py:2432-2480 | libs/core/langchain_core/runnables/base.py:2500-2555 — These two members are one piece of code written twice and then edited apart: 49 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (49 corresponding lines) libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:323— libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:323-379 | libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py:545-593 — These two members are one piece of code written twice and then edited apart: 49 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (41 corresponding lines) · ×2
Edited copy of a member (41 corresponding lines) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:148— libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:148-188 | libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:205-245 — These two members are one piece of code written twice and then edited apart: 41 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (41 corresponding lines) libs/partners/openai/langchain_openai/chat_models/base.py:4532— libs/partners/openai/langchain_openai/chat_models/base.py:4532-4576 | libs/partners/openai/langchain_openai/chat_models/base.py:4582-4622 — These two members are one piece of code written twice and then edited apart: 41 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (69 corresponding lines) · ×2
Edited copy of a member (69 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:552— libs/langchain/langchain_classic/chat_models/base.py:552-620 | libs/langchain_v1/langchain/chat_models/base.py:548-620 — These two members are one piece of code written twice and then edited apart: 69 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (69 corresponding lines) libs/core/langchain_core/callbacks/manager.py:2594— libs/core/langchain_core/callbacks/manager.py:2594-2707 | libs/core/langchain_core/callbacks/manager.py:2713-2781 — These two members are one piece of code written twice and then edited apart: 69 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (76 corresponding lines) · ×2
Edited copy of a member (76 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:552— libs/partners/qdrant/langchain_qdrant/vectorstores.py:552-627 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:641-722 — These two members are one piece of code written twice and then edited apart: 76 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (76 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2289— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2289-2365 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2373-2448 — These two members are one piece of code written twice and then edited apart: 76 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (50 corresponding lines) · ×2
Edited copy of a member (50 corresponding lines) libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:141— libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:141-190 | libs/langchain_v1/langchain/agents/middleware/tool_emulator.py:197-248 — These two members are one piece of code written twice and then edited apart: 50 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (50 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:824— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:824-883 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:887-936 — These two members are one piece of code written twice and then edited apart: 50 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (39 corresponding lines) · ×2
Edited copy of a member (39 corresponding lines) libs/partners/exa/langchain_exa/tools.py:123— libs/partners/exa/langchain_exa/tools.py:123-161 | libs/partners/exa/langchain_exa/tools.py:204-242 — These two members are one piece of code written twice and then edited apart: 39 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (39 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:329— libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:329-367 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:684-722 — These two members are one piece of code written twice and then edited apart: 39 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (11 corresponding lines) · ×2
Edited copy of a member (11 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py:372— libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py:372-382 | libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py:391-403 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) libs/langchain/langchain_classic/retrievers/document_compressors/cohere_rerank.py:108— libs/langchain/langchain_classic/retrievers/document_compressors/cohere_rerank.py:108-124 | libs/partners/fireworks/langchain_fireworks/rerank.py:207-217 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (37–38 lines × 2) libs/langchain_v1/langchain/agents/factory.py:287— libs/langchain_v1/langchain/agents/factory.py:287-324 | libs/langchain_v1/langchain/agents/factory.py:379-415 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note first that the copies are not typed on the same thing: the declarations holding them bind `handlers` to `Sequence[_ModelCallHandler[ContextT]]` in one and `Sequence[_AsyncModelCallHandler[ContextT]]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (37–38 lines × 2) REDACTED:1408— REDACTED:1408-1445 | REDACTED:1554-1590 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (35–36 lines × 2) libs/partners/chroma/langchain_chroma/vectorstores.py:561— libs/partners/chroma/langchain_chroma/vectorstores.py:561-595 | libs/partners/chroma/langchain_chroma/vectorstores.py:647-682 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/chroma/langchain_chroma/vectorstores.py:561` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (35–36 lines × 2) REDACTED:164— REDACTED:164-199 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:201-235 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (31 lines × 2) libs/core/langchain_core/language_models/llms.py:935— libs/core/langchain_core/language_models/llms.py:935-965 | libs/core/langchain_core/language_models/llms.py:1205-1235 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/llms.py:935` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (31 lines × 2) libs/core/langchain_core/runnables/base.py:3661— libs/core/langchain_core/runnables/base.py:3661-3691 | libs/core/langchain_core/runnables/fallbacks.py:378-408 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (27–29 lines × 2) libs/langchain_v1/langchain/agents/middleware/model_retry.py:241— libs/langchain_v1/langchain/agents/middleware/model_retry.py:241-267 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:323-351 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/model_retry.py` and `libs/langchain_v1/langchain/agents/middleware/tool_retry.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 81 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `handler` to `Callable[[ModelRequest[ContextT]], ModelResponse[ResponseT]]` in one and `Callable[[ToolCallRequest], ToolMessage | Command[Any]]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (27–29 lines × 2) libs/langchain_v1/langchain/agents/middleware/model_retry.py:295— libs/langchain_v1/langchain/agents/middleware/model_retry.py:295-321 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:387-415 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/model_retry.py` and `libs/langchain_v1/langchain/agents/middleware/tool_retry.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 81 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `handler` to `Callable[[ModelRequest[ContextT]], Awaitable[ModelResponse[ResponseT]]]` in one and `Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (28 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:691— libs/langchain/langchain_classic/chat_models/base.py:691-718 | libs/langchain_v1/langchain/chat_models/base.py:686-713 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (28 lines × 2) libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:218— libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:218-245 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:271-298 — `libs/langchain/langchain_classic/agents/openai_functions_agent/base.py` and `libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 75 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (26 lines × 2) libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:40— libs/langchain/langchain_classic/callbacks/streaming_aiter_final_only.py:40-65 | libs/langchain/langchain_classic/callbacks/streaming_stdout_final_only.py:41-66 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (26 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:361— libs/langchain/langchain_classic/chat_models/base.py:361-386 | libs/langchain_v1/langchain/chat_models/base.py:508-533 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23–25 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:596— libs/langchain/langchain_classic/chat_models/base.py:596-620 | libs/langchain_v1/langchain/chat_models/base.py:598-620 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chat_models/base.py:596` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23–25 lines × 2) libs/langchain_v1/langchain/agents/middleware/types.py:1966— libs/langchain_v1/langchain/agents/middleware/types.py:1966-1990 | libs/langchain_v1/langchain/agents/middleware/types.py:2156-2178 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain_v1/langchain/agents/middleware/types.py:1966` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: the declarations holding them bind `handler` to `Callable[[ModelRequest[ContextT]], Awaitable[ModelResponse[ResponseT]]]` in one and `Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (19–20 lines × 2) libs/core/langchain_core/language_models/chat_models.py:785— libs/core/langchain_core/language_models/chat_models.py:785-803 | libs/core/langchain_core/language_models/chat_models.py:917-936 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (19–20 lines × 2) libs/core/langchain_core/language_models/chat_models.py:2042— libs/core/langchain_core/language_models/chat_models.py:2042-2060 | libs/core/langchain_core/language_models/chat_models.py:2198-2217 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_models.py:2198` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18–19 lines × 2) libs/langchain/langchain_classic/agents/chat/base.py:157— libs/langchain/langchain_classic/agents/chat/base.py:157-174 | libs/langchain/langchain_classic/agents/mrkl/base.py:141-159 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/chat/base.py:157` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: `LLMChain` names `langchain_classic.chains` in one and `langchain_classic.chains.llm` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (18–19 lines × 2) libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:61— libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:61-79 | libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:93-110 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/retrievers/document_compressors/chain_filter.py:61` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17–18 lines × 2) libs/partners/chroma/langchain_chroma/vectorstores.py:543— libs/partners/chroma/langchain_chroma/vectorstores.py:543-559 | libs/partners/chroma/langchain_chroma/vectorstores.py:628-645 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/chroma/langchain_chroma/vectorstores.py:543` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (17–18 lines × 2) libs/partners/qdrant/langchain_qdrant/qdrant.py:466— libs/partners/qdrant/langchain_qdrant/qdrant.py:466-483 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1404-1420 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/qdrant/langchain_qdrant/qdrant.py:466` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 3) libs/core/langchain_core/messages/block_translators/langchain_v0.py:116— libs/core/langchain_core/messages/block_translators/langchain_v0.py:116-132 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:186-202 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:256-272 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/langchain_v0.py:116` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 3) REDACTED:1975— REDACTED:1975-1991 | libs/partners/groq/langchain_groq/chat_models.py:1242-1258 | libs/partners/ollama/langchain_ollama/chat_models.py:1699-1715 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1975` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–17 lines × 2) libs/core/langchain_core/messages/block_translators/openai.py:456— libs/core/langchain_core/messages/block_translators/openai.py:456-472 | libs/core/langchain_core/messages/block_translators/openai.py:482-496 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/openai.py:456` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (15–17 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:1997— libs/partners/openai/langchain_openai/chat_models/base.py:1997-2011 | libs/partners/openai/langchain_openai/chat_models/base.py:2300-2316 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openai/langchain_openai/chat_models/base.py:2300` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 17) libs/core/scripts/check_version.py:28— libs/core/scripts/check_version.py:28-43 | libs/langchain_v1/scripts/check_version.py:28-43 | libs/partners/anthropic/scripts/check_version.py:28-43 | libs/partners/chroma/scripts/check_version.py:28-43 | libs/partners/deepseek/scripts/check_version.py:28-43 | libs/partners/exa/scripts/check_version.py:28-43 | libs/partners/fireworks/scripts/check_version.py:28-43 | libs/partners/groq/scripts/check_version.py:28-43 | libs/partners/huggingface/scripts/check_version.py:28-43 | libs/partners/mistralai/scripts/check_version.py:28-43 | libs/partners/nomic/scripts/check_version.py:28-43 | libs/partners/ollama/scripts/check_version.py:28-43 | libs/partners/openai/scripts/check_version.py:28-43 | libs/partners/openrouter/scripts/check_version.py:28-43 | libs/partners/perplexity/scripts/check_version.py:28-43 | libs/partners/qdrant/scripts/check_version.py:28-43 | libs/partners/xai/scripts/check_version.py:28-43 — before extracting anything, compare `libs/core/scripts/check_version.py` and `libs/partners/anthropic/scripts/check_version.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 58 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 17) libs/core/scripts/check_version.py:46— libs/core/scripts/check_version.py:46-61 | libs/langchain_v1/scripts/check_version.py:46-61 | libs/partners/anthropic/scripts/check_version.py:46-61 | libs/partners/chroma/scripts/check_version.py:46-61 | libs/partners/deepseek/scripts/check_version.py:46-61 | libs/partners/exa/scripts/check_version.py:46-61 | libs/partners/fireworks/scripts/check_version.py:46-61 | libs/partners/groq/scripts/check_version.py:46-61 | libs/partners/huggingface/scripts/check_version.py:46-61 | libs/partners/mistralai/scripts/check_version.py:46-61 | libs/partners/nomic/scripts/check_version.py:46-61 | libs/partners/ollama/scripts/check_version.py:46-61 | libs/partners/openai/scripts/check_version.py:46-61 | libs/partners/openrouter/scripts/check_version.py:46-61 | libs/partners/perplexity/scripts/check_version.py:46-61 | libs/partners/qdrant/scripts/check_version.py:46-61 | libs/partners/xai/scripts/check_version.py:46-61 — before extracting anything, compare `libs/core/scripts/check_version.py` and `libs/partners/anthropic/scripts/check_version.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 58 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15–16 lines × 2) libs/core/langchain_core/vectorstores/base.py:77— libs/core/langchain_core/vectorstores/base.py:77-91 | libs/core/langchain_core/vectorstores/base.py:216-231 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15–16 lines × 2) libs/langchain_v1/langchain/agents/factory.py:1523— libs/langchain_v1/langchain/agents/factory.py:1523-1538 | libs/langchain_v1/langchain/agents/factory.py:1583-1597 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14–16 lines × 2) libs/partners/chroma/langchain_chroma/vectorstores.py:40— libs/partners/chroma/langchain_chroma/vectorstores.py:40-55 | libs/partners/chroma/langchain_chroma/vectorstores.py:60-73 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14–16 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:1427— libs/partners/groq/langchain_groq/chat_models.py:1427-1442 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1307-1320 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/groq/langchain_groq/chat_models.py:1427` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 3) libs/core/langchain_core/vectorstores/utils.py:151— libs/core/langchain_core/vectorstores/utils.py:151-163 | libs/partners/chroma/langchain_chroma/vectorstores.py:140-152 | libs/partners/qdrant/langchain_qdrant/_utils.py:27-39 — before extracting anything, compare `libs/partners/chroma/langchain_chroma/vectorstores.py` and `libs/partners/qdrant/langchain_qdrant/_utils.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 61 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 3) libs/core/langchain_core/messages/block_translators/anthropic.py:14— libs/core/langchain_core/messages/block_translators/anthropic.py:14-26 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:18-30 | libs/core/langchain_core/messages/block_translators/groq.py:15-27 — before extracting anything, compare `libs/core/langchain_core/messages/block_translators/anthropic.py` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11–12 lines × 2) libs/core/langchain_core/language_models/_compat_bridge.py:309— libs/core/langchain_core/language_models/_compat_bridge.py:309-319 | libs/core/langchain_core/language_models/_compat_bridge.py:321-332 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11–12 lines × 2) libs/core/langchain_core/output_parsers/transform.py:129— libs/core/langchain_core/output_parsers/transform.py:129-140 | libs/core/langchain_core/output_parsers/transform.py:157-167 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 4) libs/core/langchain_core/language_models/chat_models.py:857— libs/core/langchain_core/language_models/chat_models.py:857-868 | libs/core/langchain_core/language_models/chat_models.py:994-1004 | libs/core/langchain_core/language_models/chat_models.py:2044-2054 | libs/core/langchain_core/language_models/chat_models.py:2201-2211 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/language_models/chat_models.py:2212` calls `ChatGenerationChunk` and `libs/core/langchain_core/language_models/chat_models.py:869` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11 lines × 4) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:753— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:753-765 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:771-781 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:787-797 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:821-831 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (10–11 lines × 3) libs/core/langchain_core/messages/block_translators/openai.py:805— libs/core/langchain_core/messages/block_translators/openai.py:805-814 | libs/core/langchain_core/messages/block_translators/openai.py:846-855 | libs/core/langchain_core/messages/block_translators/openai.py:889-899 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/messages/block_translators/openai.py:900` calls `cast` and `libs/core/langchain_core/messages/block_translators/openai.py:816` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10–11 lines × 3) libs/langchain/langchain_classic/chains/loading.py:75— libs/langchain/langchain_classic/chains/loading.py:75-84 | libs/langchain/langchain_classic/chains/loading.py:267-276 | libs/langchain/langchain_classic/chains/loading.py:321-331 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/chains/loading.py:267` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (10 lines × 3) REDACTED:603— REDACTED:603-612 | libs/partners/groq/langchain_groq/chat_models.py:1520-1529 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:294-303 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:603` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 3) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1373— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1373-1382 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1384-1393 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1395-1404 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (6 lines × 3) libs/core/langchain_core/vectorstores/utils.py:144— libs/core/langchain_core/vectorstores/utils.py:144-149 | libs/partners/chroma/langchain_chroma/vectorstores.py:133-138 | libs/partners/qdrant/langchain_qdrant/_utils.py:20-25 — before extracting anything, compare `libs/partners/chroma/langchain_chroma/vectorstores.py` and `libs/partners/qdrant/langchain_qdrant/_utils.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 61 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (6 lines × 3) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1734— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1734-1739 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1796-1801 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1841-1846 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (5 lines × 3) libs/core/langchain_core/output_parsers/base.py:357— libs/core/langchain_core/output_parsers/base.py:357-361 | libs/core/langchain_core/prompts/base.py:363-374 | libs/langchain/langchain_classic/chains/base.py:736-757 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (5 lines × 3) libs/core/langchain_core/runnables/base.py:3876— libs/core/langchain_core/runnables/base.py:3876-3880 | libs/core/langchain_core/runnables/base.py:5557-5561 | libs/core/langchain_core/runnables/passthrough.py:342-346 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
X1 · Async correctness· Task from `asyncio.get_running_loop().create_task` is not kept · ×2
Task from `asyncio.get_running_loop().create_task` is not kept libs/partners/openai/langchain_openai/chat_models/_client_utils.py:383— The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception.
Task from `asyncio.get_running_loop().create_task` is not kept libs/partners/anthropic/langchain_anthropic/_client_utils.py:41— The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception.
chat_models._format_messages (cyclomatic 95) libs/partners/anthropic/langchain_anthropic/chat_models.py:716— chat_models._format_messages has cyclomatic complexity 95 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
factory.create_agent (cyclomatic 78) libs/langchain_v1/langchain/agents/factory.py:895— factory.create_agent has cyclomatic complexity 78 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils.convert_to_openai_messages (cyclomatic 77) REDACTED:1562— utils.convert_to_openai_messages has cyclomatic complexity 77 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatAnthropic._get_request_payload (cyclomatic 73) libs/partners/anthropic/langchain_anthropic/chat_models.py:1876— ChatAnthropic._get_request_payload has cyclomatic complexity 73 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
langchain_v0._convert_legacy_v0_content_block_to_v1 (cyclomatic 57) libs/core/langchain_core/messages/block_translators/langchain_v0.py:46— langchain_v0._convert_legacy_v0_content_block_to_v1 has cyclomatic complexity 57 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
manager._configure (cyclomatic 55) libs/core/langchain_core/callbacks/manager.py:2377— manager._configure has cyclomatic complexity 55 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._construct_responses_api_input (cyclomatic 54) libs/partners/openai/langchain_openai/chat_models/base.py:4938— base._construct_responses_api_input has cyclomatic complexity 54 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
google_genai._convert_to_v1_from_genai (cyclomatic 52) libs/core/langchain_core/messages/block_translators/google_genai.py:320— google_genai._convert_to_v1_from_genai has cyclomatic complexity 52 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatAnthropic._make_message_chunk_from_anthropic_event (cyclomatic 50) libs/partners/anthropic/langchain_anthropic/chat_models.py:2306— ChatAnthropic._make_message_chunk_from_anthropic_event has cyclomatic complexity 50 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
langchain_classic.__getattr__ (cyclomatic 47) libs/langchain/langchain_classic/__init__.py:45— langchain_classic.__getattr__ has cyclomatic complexity 47 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
_compat._consolidate_calls (cyclomatic 47) libs/partners/openai/langchain_openai/chat_models/_compat.py:296— _compat._consolidate_calls has cyclomatic complexity 47 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_from_v1_to_responses (cyclomatic 43) libs/partners/openai/langchain_openai/chat_models/_compat.py:437— _compat._convert_from_v1_to_responses has cyclomatic complexity 43 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Crawler.crawl (cyclomatic 42) libs/langchain/langchain_classic/chains/natbot/crawler.py:150— Crawler.crawl has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_from_v1_to_anthropic (cyclomatic 41) libs/partners/anthropic/langchain_anthropic/_compat.py:106— _compat._convert_from_v1_to_anthropic has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._convert_responses_chunk_to_generation_chunk (cyclomatic 41) libs/partners/openai/langchain_openai/chat_models/base.py:5408— base._convert_responses_chunk_to_generation_chunk has cyclomatic complexity 41 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
utils._first_max_tokens (cyclomatic 38) REDACTED:1988— utils._first_max_tokens has cyclomatic complexity 38 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
api.aindex (cyclomatic 37) libs/core/langchain_core/indexing/api.py:635— api.aindex has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HuggingFacePipeline.from_model_id (cyclomatic 37) libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py:113— HuggingFacePipeline.from_model_id has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._construct_responses_api_payload (cyclomatic 36) libs/partners/openai/langchain_openai/chat_models/base.py:4669— base._construct_responses_api_payload has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
api.index (cyclomatic 35) libs/core/langchain_core/indexing/api.py:296— api.index has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_ChatModelStreamBase._push_content_block_delta (cyclomatic 35) libs/core/langchain_core/language_models/chat_model_stream.py:750— _ChatModelStreamBase._push_content_block_delta has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatModel._generate_with_cache (cyclomatic 35) libs/core/langchain_core/language_models/chat_models.py:1935— BaseChatModel._generate_with_cache has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (BaseChatModel._agenerate_with_cache) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatModel._agenerate_with_cache (cyclomatic 35) libs/core/langchain_core/language_models/chat_models.py:2094— BaseChatModel._agenerate_with_cache has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (BaseChatModel._generate_with_cache) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_compat_bridge._accumulate (cyclomatic 34) libs/core/langchain_core/language_models/_compat_bridge.py:297— _compat_bridge._accumulate has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
mustache.render (cyclomatic 34) libs/core/langchain_core/utils/mustache.py:468— mustache.render has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils.get_buffer_string (cyclomatic 32) REDACTED:297— utils.get_buffer_string has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_chunk_to_message_chunk (cyclomatic 32) libs/partners/mistralai/langchain_mistralai/chat_models.py:350— chat_models._convert_chunk_to_message_chunk has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._get_builtin_translator (cyclomatic 31) libs/langchain/langchain_classic/retrievers/self_query/base.py:29— base._get_builtin_translator has cyclomatic complexity 31 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatPerplexity._stream (cyclomatic 31) libs/partners/perplexity/langchain_perplexity/chat_models.py:1200— ChatPerplexity._stream has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (ChatPerplexity._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatPerplexity._astream (cyclomatic 31) libs/partners/perplexity/langchain_perplexity/chat_models.py:1317— ChatPerplexity._astream has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (ChatPerplexity._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
function_calling.convert_to_openai_function (cyclomatic 29) libs/core/langchain_core/utils/function_calling.py:377— function_calling.convert_to_openai_function has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_annotation_from_v1 (cyclomatic 29) libs/partners/anthropic/langchain_anthropic/_compat.py:19— _compat._convert_annotation_from_v1 has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_chunk_to_message_chunk (cyclomatic 29) libs/partners/groq/langchain_groq/chat_models.py:1465— chat_models._convert_chunk_to_message_chunk has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils._format_content_block_xml (cyclomatic 28) REDACTED:142— utils._format_content_block_xml has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._format_data_content_block (cyclomatic 28) libs/partners/anthropic/langchain_anthropic/chat_models.py:393— chat_models._format_data_content_block has cyclomatic complexity 28 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatOllama._convert_messages_to_ollama_messages (cyclomatic 28) libs/partners/ollama/langchain_ollama/chat_models.py:970— ChatOllama._convert_messages_to_ollama_messages has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RecursiveCharacterTextSplitter.get_separators_for_language (cyclomatic 28) libs/text-splitters/langchain_text_splitters/character.py:183— RecursiveCharacterTextSplitter.get_separators_for_language has cyclomatic complexity 28 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
BaseLLM.generate (cyclomatic 27) libs/core/langchain_core/language_models/llms.py:852— BaseLLM.generate has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils.filter_messages (cyclomatic 27) REDACTED:870— utils.filter_messages has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseTool._parse_input (cyclomatic 27) libs/core/langchain_core/tools/base.py:779— BaseTool._parse_input has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._construct_lc_result_from_responses_api (cyclomatic 27) libs/partners/openai/langchain_openai/chat_models/base.py:5195— base._construct_lc_result_from_responses_api has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseLLM.agenerate (cyclomatic 26) libs/core/langchain_core/language_models/llms.py:1133— BaseLLM.agenerate has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
openai._convert_from_v03_ai_message (cyclomatic 26) libs/core/langchain_core/messages/block_translators/openai.py:295— openai._convert_from_v03_ai_message has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils.count_tokens_approximately (cyclomatic 26) REDACTED:2262— utils.count_tokens_approximately has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_chunk_to_message_chunk (cyclomatic 26) REDACTED:545— chat_models._convert_chunk_to_message_chunk has cyclomatic complexity 26 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
AzureChatOpenAI.validate_environment (cyclomatic 26) libs/partners/openai/langchain_openai/chat_models/azure.py:627— AzureChatOpenAI.validate_environment has cyclomatic complexity 26 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
base._init_chat_model_helper (cyclomatic 25) libs/langchain/langchain_classic/chat_models/base.py:389— base._init_chat_model_helper has cyclomatic complexity 25 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
BaseChatOpenAI.validate_environment (cyclomatic 25) libs/partners/openai/langchain_openai/chat_models/base.py:1408— BaseChatOpenAI.validate_environment has cyclomatic complexity 25 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
base._convert_message_to_dict (cyclomatic 25) libs/partners/openai/langchain_openai/chat_models/base.py:476— base._convert_message_to_dict has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_responses_stream_event_to_chunk (cyclomatic 25) libs/partners/perplexity/langchain_perplexity/chat_models.py:507— chat_models._convert_responses_stream_event_to_chunk has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MarkdownHeaderTextSplitter.split_text (cyclomatic 25) libs/text-splitters/langchain_text_splitters/markdown.py:134— MarkdownHeaderTextSplitter.split_text has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_policy._ip_in_blocked_networks (cyclomatic 24) libs/core/langchain_core/_security/_policy.py:145— _policy._ip_in_blocked_networks has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
openai.convert_to_openai_data_block (cyclomatic 24) libs/core/langchain_core/messages/block_translators/openai.py:58— openai.convert_to_openai_data_block has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RunnableSequence.batch (cyclomatic 24) libs/core/langchain_core/runnables/base.py:3525— RunnableSequence.batch has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
config.merge_configs (cyclomatic 24) libs/core/langchain_core/runnables/config.py:431— config.merge_configs has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
function_calling._parse_google_docstring (cyclomatic 24) libs/core/langchain_core/utils/function_calling.py:735— function_calling._parse_google_docstring has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_message_to_dict (cyclomatic 24) libs/partners/groq/langchain_groq/chat_models.py:1375— chat_models._convert_message_to_dict has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RunnableSequence.abatch (cyclomatic 23) libs/core/langchain_core/runnables/base.py:3653— RunnableSequence.abatch has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_merge.merge_lists (cyclomatic 23) libs/core/langchain_core/utils/_merge.py:98— _merge.merge_lists has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatAnthropic.bind_tools (cyclomatic 23) libs/partners/anthropic/langchain_anthropic/chat_models.py:2684— ChatAnthropic.bind_tools has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._format_message_content (cyclomatic 23) libs/partners/openai/langchain_openai/chat_models/base.py:385— base._format_message_content has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatAnthropic._format_output (cyclomatic 22) libs/partners/anthropic/langchain_anthropic/chat_models.py:2538— ChatAnthropic._format_output has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatFireworks._stream (cyclomatic 22) REDACTED:1385— ChatFireworks._stream has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (ChatFireworks._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatFireworks._astream (cyclomatic 22) REDACTED:1530— ChatFireworks._astream has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (ChatFireworks._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_compat._convert_to_v1_from_mistral (cyclomatic 22) libs/partners/mistralai/langchain_mistralai/_compat.py:86— _compat._convert_to_v1_from_mistral has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_message_to_mistral_chat_message (cyclomatic 22) libs/partners/mistralai/langchain_mistralai/chat_models.py:534— chat_models._convert_message_to_mistral_chat_message has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI.bind_tools (cyclomatic 22) libs/partners/openai/langchain_openai/chat_models/base.py:2511— BaseChatOpenAI.bind_tools has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_message_to_dict (cyclomatic 22) libs/partners/openrouter/langchain_openrouter/chat_models.py:1271— chat_models._convert_message_to_dict has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_utils.is_openai_data_block (cyclomatic 21) libs/core/langchain_core/language_models/_utils.py:33— _utils.is_openai_data_block has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_ChatModelStreamBase._push_content_block_finish (cyclomatic 21) libs/core/langchain_core/language_models/chat_model_stream.py:941— _ChatModelStreamBase._push_content_block_finish has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils._create_message_from_message_type (cyclomatic 21) REDACTED:606— utils._create_message_from_message_type has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
graph_mermaid.draw_mermaid (cyclomatic 21) libs/core/langchain_core/runnables/graph_mermaid.py:86— graph_mermaid.draw_mermaid has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatAnthropic._assert_valid_model_configuration (cyclomatic 21) libs/partners/anthropic/langchain_anthropic/chat_models.py:1804— ChatAnthropic._assert_valid_model_configuration has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_from_v1_to_groq (cyclomatic 21) libs/partners/groq/langchain_groq/_compat.py:9— _compat._convert_from_v1_to_groq has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_from_v1_to_mistral (cyclomatic 21) libs/partners/mistralai/langchain_mistralai/_compat.py:12— _compat._convert_from_v1_to_mistral has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat._convert_to_v03_ai_message (cyclomatic 21) libs/partners/openai/langchain_openai/chat_models/_compat.py:92— _compat._convert_to_v03_ai_message has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI.get_num_tokens_from_messages (cyclomatic 21) libs/partners/openai/langchain_openai/chat_models/base.py:2409— BaseChatOpenAI.get_num_tokens_from_messages has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_chunk_to_message_chunk (cyclomatic 21) libs/partners/openrouter/langchain_openrouter/chat_models.py:1414— chat_models._convert_chunk_to_message_chunk has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Reviver.__call__ (cyclomatic 20) libs/core/langchain_core/load/load.py:460— Reviver.__call__ has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_StringImageMessagePromptTemplate.from_template (cyclomatic 20) libs/core/langchain_core/prompts/chat.py:412— _StringImageMessagePromptTemplate.from_template has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base.create_schema_from_function (cyclomatic 20) libs/core/langchain_core/tools/base.py:264— base.create_schema_from_function has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
json.parse_partial_json (cyclomatic 20) libs/core/langchain_core/utils/json.py:60— json.parse_partial_json has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
huggingface._convert_chunk_to_message_chunk (cyclomatic 20) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:250— huggingface._convert_chunk_to_message_chunk has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
base._convert_delta_to_message_chunk (cyclomatic 20) libs/partners/openai/langchain_openai/chat_models/base.py:558— base._convert_delta_to_message_chunk has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
AzureOpenAI.validate_environment (cyclomatic 20) libs/partners/openai/langchain_openai/llms/azure.py:127— AzureOpenAI.validate_environment has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatPerplexity._to_responses_payload (cyclomatic 20) libs/partners/perplexity/langchain_perplexity/chat_models.py:1047— ChatPerplexity._to_responses_payload has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Serializable.to_json (cyclomatic 19) libs/core/langchain_core/load/serializable.py:228— Serializable.to_json has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RunnableWithFallbacks.batch (cyclomatic 19) libs/core/langchain_core/runnables/fallbacks.py:265— RunnableWithFallbacks.batch has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StructuredTool.from_function (cyclomatic 19) libs/core/langchain_core/tools/structured.py:188— StructuredTool.from_function has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
_merge.merge_dicts (cyclomatic 19) libs/core/langchain_core/utils/_merge.py:6— _merge.merge_dicts has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
PIIMiddleware.before_model (cyclomatic 19) libs/langchain_v1/langchain/agents/middleware/pii.py:721— PIIMiddleware.before_model has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_message_to_dict (cyclomatic 19) REDACTED:369— chat_models._convert_message_to_dict has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI._create_chat_result (cyclomatic 19) libs/partners/openai/langchain_openai/chat_models/base.py:2066— BaseChatOpenAI._create_chat_result has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI.with_structured_output (cyclomatic 19) libs/partners/openai/langchain_openai/chat_models/base.py:2620— BaseChatOpenAI.with_structured_output has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatOpenRouter._create_chat_result (cyclomatic 19) libs/partners/openrouter/langchain_openrouter/chat_models.py:827— ChatOpenRouter._create_chat_result has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatModel.stream (cyclomatic 18) libs/core/langchain_core/language_models/chat_models.py:770— BaseChatModel.stream has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatModel.astream (cyclomatic 18) libs/core/langchain_core/language_models/chat_models.py:901— BaseChatModel.astream has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatModel._get_ls_params (cyclomatic 18) libs/core/langchain_core/language_models/chat_models.py:1545— BaseChatModel._get_ls_params has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
GenericFakeChatModel._stream (cyclomatic 18) libs/core/langchain_core/language_models/fake_chat_models.py:266— GenericFakeChatModel._stream has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
groq._convert_to_v1_from_groq (cyclomatic 18) libs/core/langchain_core/messages/block_translators/groq.py:51— groq._convert_to_v1_from_groq has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
PydanticToolsParser.parse_result (cyclomatic 18) libs/core/langchain_core/output_parsers/openai_tools.py:318— PydanticToolsParser.parse_result has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
event_stream._astream_events_implementation_v1 (cyclomatic 18) libs/core/langchain_core/tracers/event_stream.py:829— event_stream._astream_events_implementation_v1 has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HumanInTheLoopMiddleware.after_model (cyclomatic 18) libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:760— HumanInTheLoopMiddleware.after_model has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI._stream (cyclomatic 18) libs/partners/openai/langchain_openai/chat_models/base.py:1867— BaseChatOpenAI._stream has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (BaseChatOpenAI._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatOpenAI._generate (cyclomatic 18) libs/partners/openai/langchain_openai/chat_models/base.py:1944— BaseChatOpenAI._generate has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI._astream (cyclomatic 18) libs/partners/openai/langchain_openai/chat_models/base.py:2163— BaseChatOpenAI._astream has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (BaseChatOpenAI._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatPerplexity._convert_delta_to_message_chunk (cyclomatic 18) libs/partners/perplexity/langchain_perplexity/chat_models.py:1171— ChatPerplexity._convert_delta_to_message_chunk has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatPerplexity._generate (cyclomatic 18) libs/partners/perplexity/langchain_perplexity/chat_models.py:1433— ChatPerplexity._generate has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages. This shape REPEATS in the file: one other method here (ChatPerplexity._agenerate) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatPerplexity._agenerate (cyclomatic 18) libs/partners/perplexity/langchain_perplexity/chat_models.py:1500— ChatPerplexity._agenerate has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages. This shape REPEATS in the file: one other method here (ChatPerplexity._generate) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
HTMLHeaderTextSplitter._generate_documents (cyclomatic 18) libs/text-splitters/langchain_text_splitters/html.py:252— HTMLHeaderTextSplitter._generate_documents has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
openai._convert_openai_format_to_data_block (cyclomatic 17) libs/core/langchain_core/messages/block_translators/openai.py:429— openai._convert_openai_format_to_data_block has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
JsonOutputKeyToolsParser.parse_result (cyclomatic 17) libs/core/langchain_core/output_parsers/openai_tools.py:233— JsonOutputKeyToolsParser.parse_result has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RunnableWithFallbacks.abatch (cyclomatic 17) libs/core/langchain_core/runnables/fallbacks.py:361— RunnableWithFallbacks.abatch has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseTool.arun (cyclomatic 17) libs/core/langchain_core/tools/base.py:1138— BaseTool.arun has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
LogStreamCallbackHandler.include_run (cyclomatic 17) libs/core/langchain_core/tracers/log_stream.py:387— LogStreamCallbackHandler.include_run has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
function_calling._recursive_set_additional_properties_false (cyclomatic 17) libs/core/langchain_core/utils/function_calling.py:825— function_calling._recursive_set_additional_properties_false has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
mustache._get_key (cyclomatic 17) libs/core/langchain_core/utils/mustache.py:345— mustache._get_key has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._convert_dict_to_message (cyclomatic 17) libs/partners/groq/langchain_groq/chat_models.py:1532— chat_models._convert_dict_to_message has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI._convert_chunk_to_generation_chunk (cyclomatic 17) libs/partners/openai/langchain_openai/chat_models/base.py:1622— BaseChatOpenAI._convert_chunk_to_generation_chunk has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatPerplexity._default_params (cyclomatic 17) libs/partners/perplexity/langchain_perplexity/chat_models.py:933— ChatPerplexity._default_params has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
chat_models._convert_responses_to_chat_result (cyclomatic 17) libs/partners/perplexity/langchain_perplexity/chat_models.py:402— chat_models._convert_responses_to_chat_result has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_compat_bridge.chunks_to_events (cyclomatic 16) libs/core/langchain_core/language_models/_compat_bridge.py:586— _compat_bridge.chunks_to_events has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (_compat_bridge.achunks_to_events) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_compat_bridge.achunks_to_events (cyclomatic 16) libs/core/langchain_core/language_models/_compat_bridge.py:692— _compat_bridge.achunks_to_events has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (_compat_bridge.chunks_to_events) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
chat_models._format_for_tracing (cyclomatic 16) libs/core/langchain_core/language_models/chat_models.py:191— chat_models._format_for_tracing has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseLLM._get_ls_params (cyclomatic 16) libs/core/langchain_core/language_models/llms.py:334— BaseLLM._get_ls_params has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
AIMessage.content_blocks (cyclomatic 16) libs/core/langchain_core/messages/ai.py:243— AIMessage.content_blocks has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AIMessageChunk.init_tool_calls (cyclomatic 16) libs/core/langchain_core/messages/ai.py:509— AIMessageChunk.init_tool_calls has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utils.trim_messages (cyclomatic 16) REDACTED:1146— utils.trim_messages has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
_RootEventFilter.include_event (cyclomatic 16) libs/core/langchain_core/runnables/utils.py:736— _RootEventFilter.include_event has cyclomatic complexity 16 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
sys_info.print_sys_info (cyclomatic 16) libs/core/langchain_core/sys_info.py:36— sys_info.print_sys_info has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseTool.run (cyclomatic 16) libs/core/langchain_core/tools/base.py:1010— BaseTool.run has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
openapi.openapi_spec_to_openai_fn (cyclomatic 16) libs/langchain/langchain_classic/chains/openai_functions/openapi.py:97— openapi.openapi_spec_to_openai_fn has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base.fix_filter_directive (cyclomatic 16) libs/langchain/langchain_classic/chains/query_constructor/base.py:114— base.fix_filter_directive has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_redaction._apply_mask_strategy (cyclomatic 16) libs/langchain_v1/langchain/agents/middleware/_redaction.py:251— _redaction._apply_mask_strategy has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ClearToolUsesEdit.apply (cyclomatic 16) libs/langchain_v1/langchain/agents/middleware/context_editing.py:79— ClearToolUsesEdit.apply has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
chat_models._merge_messages (cyclomatic 16) libs/partners/anthropic/langchain_anthropic/chat_models.py:329— chat_models._merge_messages has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseChatOpenAI._agenerate (cyclomatic 16) libs/partners/openai/langchain_openai/chat_models/base.py:2245— BaseChatOpenAI._agenerate has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AzureOpenAIEmbeddings.validate_environment (cyclomatic 16) libs/partners/openai/langchain_openai/embeddings/azure.py:162— AzureOpenAIEmbeddings.validate_environment has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ChatOpenRouter._default_params (cyclomatic 16) libs/partners/openrouter/langchain_openrouter/chat_models.py:778— ChatOpenRouter._default_params has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Qdrant.construct_instance (cyclomatic 16) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1614— Qdrant.construct_instance has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (Qdrant.aconstruct_instance) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
Qdrant.aconstruct_instance (cyclomatic 16) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1779— Qdrant.aconstruct_instance has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top. This shape REPEATS in the file: one other method here (Qdrant.construct_instance) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
chat_models._format_messages (cognitive 278) libs/partners/anthropic/langchain_anthropic/chat_models.py:716— chat_models._format_messages has cognitive complexity 278 (threshold 15). Drivers by points: if/else 50 (204 pts), boolean chains 23, loops 6 (22 pts), error handling 3 (19 pts), ternaries 3 (10 pts) (nesting depth added 193). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
utils.convert_to_openai_messages (cognitive 204) REDACTED:1562— utils.convert_to_openai_messages has cognitive complexity 204 (threshold 15). Drivers by points: if/else 47 (175 pts), boolean chains 14, ternaries 3 (11 pts), loops 2 (4 pts) (nesting depth added 138). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
base._construct_responses_api_input (cognitive 182) libs/partners/openai/langchain_openai/chat_models/base.py:4938— base._construct_responses_api_input has cognitive complexity 182 (threshold 15). Drivers by points: if/else 34 (150 pts), loops 6 (24 pts), boolean chains 8 (nesting depth added 134). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
langchain_v0._convert_legacy_v0_content_block_to_v1 (cognitive 155) libs/core/langchain_core/messages/block_translators/langchain_v0.py:46— langchain_v0._convert_legacy_v0_content_block_to_v1 has cognitive complexity 155 (threshold 15). Drivers by points: if/else 44 (127 pts), loops 9 (27 pts), boolean chains 1 (nesting depth added 101). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._consolidate_calls (cognitive 132) libs/partners/openai/langchain_openai/chat_models/_compat.py:296— _compat._consolidate_calls has cognitive complexity 132 (threshold 15). Drivers by points: if/else 33 (114 pts), loops 4 (13 pts), boolean chains 3, error handling 1 (2 pts) (nesting depth added 91). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ChatAnthropic._get_request_payload (cognitive 125) libs/partners/anthropic/langchain_anthropic/chat_models.py:1876— ChatAnthropic._get_request_payload has cognitive complexity 125 (threshold 15). Drivers by points: if/else 50 (92 pts), boolean chains 21, ternaries 4 (7 pts), loops 3 (5 pts) (nesting depth added 47). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
google_genai._convert_to_v1_from_genai (cognitive 115) libs/core/langchain_core/messages/block_translators/google_genai.py:320— google_genai._convert_to_v1_from_genai has cognitive complexity 115 (threshold 15). Drivers by points: if/else 32 (87 pts), boolean chains 9, loops 5 (9 pts), error handling 1 (6 pts), ternaries 1 (4 pts) (nesting depth added 67). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
factory.create_agent (cognitive 108) libs/langchain_v1/langchain/agents/factory.py:895— factory.create_agent has cognitive complexity 108 (threshold 15). Drivers by points: if/else 48 (55 pts), ternaries 10 (26 pts), boolean chains 16, loops 6 (11 pts) (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils._first_max_tokens (cognitive 103) REDACTED:1988— utils._first_max_tokens has cognitive complexity 103 (threshold 15). Drivers by points: if/else 29 (81 pts), loops 6 (17 pts), boolean chains 5 (nesting depth added 63). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ChatAnthropic._make_message_chunk_from_anthropic_event (cognitive 92) libs/partners/anthropic/langchain_anthropic/chat_models.py:2306— ChatAnthropic._make_message_chunk_from_anthropic_event has cognitive complexity 92 (threshold 15). Drivers by points: if/else 32 (69 pts), boolean chains 14, ternaries 4 (9 pts) (nesting depth added 42). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
manager._configure (cognitive 90) libs/core/langchain_core/callbacks/manager.py:2377— manager._configure has cognitive complexity 90 (threshold 15). Drivers by points: if/else 24 (48 pts), boolean chains 23, ternaries 5 (9 pts), loops 3 (6 pts), error handling 1 (4 pts) (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._convert_from_v1_to_responses (cognitive 87) libs/partners/openai/langchain_openai/chat_models/_compat.py:437— _compat._convert_from_v1_to_responses has cognitive complexity 87 (threshold 15). Drivers by points: if/else 22 (71 pts), boolean chains 8, loops 3 (8 pts) (nesting depth added 54). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
_merge.merge_lists (cognitive 86) libs/core/langchain_core/utils/_merge.py:98— _merge.merge_lists has cognitive complexity 86 (threshold 15). Drivers by points: if/else 16 (67 pts), ternaries 2 (8 pts), boolean chains 7, loops 2 (4 pts) (nesting depth added 59). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
_compat._convert_from_v1_to_anthropic (cognitive 85) libs/partners/anthropic/langchain_anthropic/_compat.py:106— _compat._convert_from_v1_to_anthropic has cognitive complexity 85 (threshold 15). Drivers by points: if/else 26 (69 pts), boolean chains 8, error handling 1 (4 pts), loops 2 (4 pts) (nesting depth added 48). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._convert_annotation_from_v1 (cognitive 80) libs/partners/anthropic/langchain_anthropic/_compat.py:19— _compat._convert_annotation_from_v1 has cognitive complexity 80 (threshold 15). Drivers by points: if/else 20 (56 pts), loops 8 (24 pts) (nesting depth added 52). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Crawler.crawl (cognitive 77) libs/langchain/langchain_classic/chains/natbot/crawler.py:150— Crawler.crawl has cognitive complexity 77 (threshold 15). Drivers by points: if/else 21 (45 pts), boolean chains 14, loops 4 (8 pts), ternaries 4 (8 pts), error handling 1 (2 pts) (nesting depth added 33). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._convert_to_v1_from_mistral (cognitive 74) libs/partners/mistralai/langchain_mistralai/_compat.py:86— _compat._convert_to_v1_from_mistral has cognitive complexity 74 (threshold 15). Drivers by points: if/else 15 (62 pts), loops 3 (8 pts), boolean chains 4 (nesting depth added 52). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
base._construct_responses_api_payload (cognitive 74) libs/partners/openai/langchain_openai/chat_models/base.py:4669— base._construct_responses_api_payload has cognitive complexity 74 (threshold 15). Drivers by points: if/else 29 (59 pts), boolean chains 12, loops 2 (3 pts) (nesting depth added 31). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
utils.get_buffer_string (cognitive 72) REDACTED:297— utils.get_buffer_string has cognitive complexity 72 (threshold 15). Drivers by points: if/else 18 (51 pts), loops 3 (10 pts), boolean chains 7, ternaries 1 (4 pts) (nesting depth added 43). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
mustache.render (cognitive 71) libs/core/langchain_core/utils/mustache.py:468— mustache.render has cognitive complexity 71 (threshold 15). Drivers by points: if/else 18 (54 pts), loops 4 (13 pts), boolean chains 4 (nesting depth added 45). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
api.aindex (cognitive 70) libs/core/langchain_core/indexing/api.py:635— api.aindex has cognitive complexity 70 (threshold 15). Drivers by points: if/else 22 (46 pts), loops 7 (16 pts), boolean chains 6, error handling 1 (2 pts) (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
api.index (cognitive 69) libs/core/langchain_core/indexing/api.py:296— api.index has cognitive complexity 69 (threshold 15). Drivers by points: if/else 22 (46 pts), loops 7 (16 pts), boolean chains 5, error handling 1 (2 pts) (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatModel._generate_with_cache (cognitive 68) libs/core/langchain_core/language_models/chat_models.py:1935— BaseChatModel._generate_with_cache has cognitive complexity 68 (threshold 15). Drivers by points: if/else 19 (42 pts), loops 5 (11 pts), ternaries 5 (11 pts), boolean chains 4 (nesting depth added 35). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatModel._agenerate_with_cache) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatModel._agenerate_with_cache (cognitive 68) libs/core/langchain_core/language_models/chat_models.py:2094— BaseChatModel._agenerate_with_cache has cognitive complexity 68 (threshold 15). Drivers by points: if/else 19 (42 pts), loops 5 (11 pts), ternaries 5 (11 pts), boolean chains 4 (nesting depth added 35). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatModel._generate_with_cache) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
chat_models._convert_chunk_to_message_chunk (cognitive 68) libs/partners/mistralai/langchain_mistralai/chat_models.py:350— chat_models._convert_chunk_to_message_chunk has cognitive complexity 68 (threshold 15). Drivers by points: if/else 18 (40 pts), boolean chains 11, loops 3 (10 pts), ternaries 1 (4 pts), error handling 1 (3 pts) (nesting depth added 34). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ChatPerplexity._stream (cognitive 68) libs/partners/perplexity/langchain_perplexity/chat_models.py:1200— ChatPerplexity._stream has cognitive complexity 68 (threshold 15). Drivers by points: if/else 25 (58 pts), loops 3 (6 pts), boolean chains 4 (nesting depth added 36). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatPerplexity._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatPerplexity._astream (cognitive 68) libs/partners/perplexity/langchain_perplexity/chat_models.py:1317— ChatPerplexity._astream has cognitive complexity 68 (threshold 15). Drivers by points: if/else 25 (58 pts), loops 3 (6 pts), boolean chains 4 (nesting depth added 36). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatPerplexity._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseTool._parse_input (cognitive 63) libs/core/langchain_core/tools/base.py:779— BaseTool._parse_input has cognitive complexity 63 (threshold 15). Drivers by points: if/else 17 (48 pts), loops 4 (10 pts), ternaries 1 (4 pts), boolean chains 1 (nesting depth added 40). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
base._construct_lc_result_from_responses_api (cognitive 59) libs/partners/openai/langchain_openai/chat_models/base.py:5195— base._construct_lc_result_from_responses_api has cognitive complexity 59 (threshold 15). Drivers by points: if/else 19 (43 pts), error handling 2 (5 pts), ternaries 1 (5 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 33). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MarkdownHeaderTextSplitter.split_text (cognitive 58) libs/text-splitters/langchain_text_splitters/markdown.py:134— MarkdownHeaderTextSplitter.split_text has cognitive complexity 58 (threshold 15). Drivers by points: if/else 15 (45 pts), loops 3 (8 pts), boolean chains 5 (nesting depth added 35). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_ChatModelStreamBase._push_content_block_delta (cognitive 57) libs/core/langchain_core/language_models/chat_model_stream.py:750— _ChatModelStreamBase._push_content_block_delta has cognitive complexity 57 (threshold 15). Drivers by points: if/else 24 (55 pts), boolean chains 2 (nesting depth added 31). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
_compat._convert_from_v1_to_mistral (cognitive 57) libs/partners/mistralai/langchain_mistralai/_compat.py:12— _compat._convert_from_v1_to_mistral has cognitive complexity 57 (threshold 15). Drivers by points: if/else 12 (47 pts), boolean chains 5, loops 2 (5 pts) (nesting depth added 38). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
GenericFakeChatModel._stream (cognitive 54) libs/core/langchain_core/language_models/fake_chat_models.py:266— GenericFakeChatModel._stream has cognitive complexity 54 (threshold 15). Drivers by points: if/else 14 (39 pts), loops 4 (14 pts), boolean chains 1 (nesting depth added 35). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ChatOllama._convert_messages_to_ollama_messages (cognitive 54) libs/partners/ollama/langchain_ollama/chat_models.py:970— ChatOllama._convert_messages_to_ollama_messages has cognitive complexity 54 (threshold 15). Drivers by points: if/else 17 (44 pts), loops 3 (5 pts), ternaries 1 (3 pts), boolean chains 2 (nesting depth added 31). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat_bridge._accumulate (cognitive 51) libs/core/langchain_core/language_models/_compat_bridge.py:297— _compat_bridge._accumulate has cognitive complexity 51 (threshold 15). Drivers by points: if/else 14 (28 pts), boolean chains 17, loops 3 (6 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HuggingFacePipeline.from_model_id (cognitive 51) libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py:113— HuggingFacePipeline.from_model_id has cognitive complexity 51 (threshold 15). Drivers by points: if/else 24 (36 pts), boolean chains 9, ternaries 3 (5 pts), error handling 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils.count_tokens_approximately (cognitive 50) REDACTED:2262— utils.count_tokens_approximately has cognitive complexity 50 (threshold 15). Drivers by points: if/else 18 (39 pts), loops 3 (6 pts), boolean chains 5 (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_StringImageMessagePromptTemplate.from_template (cognitive 50) libs/core/langchain_core/prompts/chat.py:412— _StringImageMessagePromptTemplate.from_template has cognitive complexity 50 (threshold 15). Drivers by points: if/else 13 (39 pts), loops 2 (7 pts), boolean chains 4 (nesting depth added 31). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
RunnableSequence.batch (cognitive 50) libs/core/langchain_core/runnables/base.py:3525— RunnableSequence.batch has cognitive complexity 50 (threshold 15). Drivers by points: if/else 15 (31 pts), loops 5 (9 pts), ternaries 2 (6 pts), boolean chains 3, error handling 1 (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_chunk_to_message_chunk (cognitive 50) libs/partners/groq/langchain_groq/chat_models.py:1465— chat_models._convert_chunk_to_message_chunk has cognitive complexity 50 (threshold 15). Drivers by points: if/else 18 (35 pts), boolean chains 10, loops 2 (5 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._merge_messages (cognitive 49) libs/partners/anthropic/langchain_anthropic/chat_models.py:329— chat_models._merge_messages has cognitive complexity 49 (threshold 15). Drivers by points: if/else 13 (38 pts), loops 2 (6 pts), boolean chains 3, ternaries 1 (2 pts) (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
_compat._convert_to_v03_ai_message (cognitive 49) libs/partners/openai/langchain_openai/chat_models/_compat.py:92— _compat._convert_to_v03_ai_message has cognitive complexity 49 (threshold 15). Drivers by points: if/else 13 (43 pts), boolean chains 4, loops 1 (2 pts) (nesting depth added 31). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
_policy._ip_in_blocked_networks (cognitive 48) libs/core/langchain_core/_security/_policy.py:145— _policy._ip_in_blocked_networks has cognitive complexity 48 (threshold 15). Drivers by points: if/else 14 (31 pts), loops 5 (12 pts), boolean chains 5 (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnableSequence.abatch (cognitive 48) libs/core/langchain_core/runnables/base.py:3653— RunnableSequence.abatch has cognitive complexity 48 (threshold 15). Drivers by points: if/else 15 (31 pts), loops 4 (7 pts), ternaries 2 (6 pts), boolean chains 3, error handling 1 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
event_stream._astream_events_implementation_v1 (cognitive 48) libs/core/langchain_core/tracers/event_stream.py:829— event_stream._astream_events_implementation_v1 has cognitive complexity 48 (threshold 15). Drivers by points: if/else 15 (41 pts), ternaries 1 (4 pts), loops 2 (3 pts) (nesting depth added 30). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI.get_num_tokens_from_messages (cognitive 48) libs/partners/openai/langchain_openai/chat_models/base.py:2409— BaseChatOpenAI.get_num_tokens_from_messages has cognitive complexity 48 (threshold 15). Drivers by points: if/else 13 (34 pts), loops 3 (7 pts), ternaries 1 (6 pts), boolean chains 1 (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
chat_models._convert_responses_stream_event_to_chunk (cognitive 47) libs/partners/perplexity/langchain_perplexity/chat_models.py:507— chat_models._convert_responses_stream_event_to_chunk has cognitive complexity 47 (threshold 15). Drivers by points: if/else 12 (24 pts), ternaries 5 (11 pts), loops 3 (8 pts), boolean chains 4 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
langchain_classic.__getattr__ (cognitive 46) libs/langchain/langchain_classic/__init__.py:45— langchain_classic.__getattr__ has cognitive complexity 46 (threshold 15). Drivers by points: if/else 46. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
config.merge_configs (cognitive 45) libs/core/langchain_core/runnables/config.py:431— config.merge_configs has cognitive complexity 45 (threshold 15). Drivers by points: if/else 9 (25 pts), loops 4 (15 pts), boolean chains 5 (nesting depth added 27). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ChatGroq._combine_llm_outputs (cognitive 45) libs/partners/groq/langchain_groq/chat_models.py:886— ChatGroq._combine_llm_outputs has cognitive complexity 45 (threshold 15). Drivers by points: if/else 12 (33 pts), loops 3 (10 pts), boolean chains 2 (nesting depth added 28). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
BaseChatModel.stream (cognitive 44) libs/core/langchain_core/language_models/chat_models.py:770— BaseChatModel.stream has cognitive complexity 44 (threshold 15). Drivers by points: if/else 12 (30 pts), loops 2 (6 pts), boolean chains 3, ternaries 1 (3 pts), error handling 1 (2 pts) (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils.filter_messages (cognitive 44) REDACTED:870— utils.filter_messages has cognitive complexity 44 (threshold 15). Drivers by points: if/else 9 (28 pts), boolean chains 15, loops 1 (nesting depth added 19). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
chat_models._format_for_tracing (cognitive 43) libs/core/langchain_core/language_models/chat_models.py:191— chat_models._format_for_tracing has cognitive complexity 43 (threshold 15). Drivers by points: if/else 7 (35 pts), boolean chains 4, loops 2 (4 pts) (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
function_calling._parse_google_docstring (cognitive 43) libs/core/langchain_core/utils/function_calling.py:735— function_calling._parse_google_docstring has cognitive complexity 43 (threshold 15). Drivers by points: if/else 14 (33 pts), boolean chains 6, loops 2 (4 pts) (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HTMLHeaderTextSplitter._generate_documents (cognitive 42) libs/text-splitters/langchain_text_splitters/html.py:252— HTMLHeaderTextSplitter._generate_documents has cognitive complexity 42 (threshold 15). Drivers by points: if/else 14 (31 pts), loops 3 (7 pts), error handling 1 (3 pts), boolean chains 1 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai.convert_to_openai_data_block (cognitive 41) libs/core/langchain_core/messages/block_translators/openai.py:58— openai.convert_to_openai_data_block has cognitive complexity 41 (threshold 15). Drivers by points: if/else 14 (27 pts), ternaries 3 (9 pts), boolean chains 5 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils._format_content_block_xml (cognitive 41) REDACTED:142— utils._format_content_block_xml has cognitive complexity 41 (threshold 15). Drivers by points: if/else 21 (32 pts), boolean chains 5, ternaries 2 (4 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PIIMiddleware.before_model (cognitive 41) libs/langchain_v1/langchain/agents/middleware/pii.py:721— PIIMiddleware.before_model has cognitive complexity 41 (threshold 15). Drivers by points: if/else 13 (32 pts), loops 3 (7 pts), boolean chains 2 (nesting depth added 23). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
chat_models._convert_message_to_mistral_chat_message (cognitive 41) libs/partners/mistralai/langchain_mistralai/chat_models.py:534— chat_models._convert_message_to_mistral_chat_message has cognitive complexity 41 (threshold 15). Drivers by points: if/else 17 (30 pts), ternaries 2 (6 pts), loops 1 (3 pts), boolean chains 2 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openapi.openapi_spec_to_openai_fn (cognitive 40) libs/langchain/langchain_classic/chains/openai_functions/openapi.py:97— openapi.openapi_spec_to_openai_fn has cognitive complexity 40 (threshold 15). Drivers by points: if/else 5 (17 pts), loops 6 (16 pts), ternaries 1 (5 pts), boolean chains 1, error handling 1 (nesting depth added 26). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnableBranch.stream (cognitive 39) libs/core/langchain_core/runnables/branch.py:292— RunnableBranch.stream has cognitive complexity 39 (threshold 15). Drivers by points: if/else 7 (20 pts), error handling 3 (12 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableBranch.astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
RunnableBranch.astream (cognitive 39) libs/core/langchain_core/runnables/branch.py:376— RunnableBranch.astream has cognitive complexity 39 (threshold 15). Drivers by points: if/else 7 (20 pts), error handling 3 (12 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableBranch.stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
groq._convert_to_v1_from_groq (cognitive 38) libs/core/langchain_core/messages/block_translators/groq.py:51— groq._convert_to_v1_from_groq has cognitive complexity 38 (threshold 15). Drivers by points: if/else 9 (22 pts), error handling 2 (10 pts), boolean chains 4, loops 1 (2 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._convert_from_v03_ai_message (cognitive 38) libs/core/langchain_core/messages/block_translators/openai.py:295— openai._convert_from_v03_ai_message has cognitive complexity 38 (threshold 15). Drivers by points: if/else 15 (23 pts), boolean chains 10, loops 4 (5 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatFireworks._stream (cognitive 36) REDACTED:1385— ChatFireworks._stream has cognitive complexity 36 (threshold 15). Drivers by points: if/else 12 (27 pts), boolean chains 6, error handling 2, loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatFireworks._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatFireworks._astream (cognitive 36) REDACTED:1530— ChatFireworks._astream has cognitive complexity 36 (threshold 15). Drivers by points: if/else 12 (27 pts), boolean chains 6, error handling 2, loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatFireworks._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_compat._convert_from_v1_to_groq (cognitive 35) libs/partners/groq/langchain_groq/_compat.py:9— _compat._convert_from_v1_to_groq has cognitive complexity 35 (threshold 15). Drivers by points: if/else 10 (25 pts), boolean chains 5, loops 2 (5 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
function_calling._recursive_set_additional_properties_false (cognitive 34) libs/core/langchain_core/utils/function_calling.py:825— function_calling._recursive_set_additional_properties_false has cognitive complexity 34 (threshold 15). Drivers by points: if/else 8 (16 pts), loops 5 (15 pts), boolean chains 3 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_redaction._apply_mask_strategy (cognitive 34) libs/langchain_v1/langchain/agents/middleware/_redaction.py:251— _redaction._apply_mask_strategy has cognitive complexity 34 (threshold 15). Drivers by points: ternaries 6 (19 pts), if/else 7 (14 pts), loops 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SummarizationMiddleware._should_summarize (cognitive 34) libs/langchain_v1/langchain/agents/middleware/summarization.py:698— SummarizationMiddleware._should_summarize has cognitive complexity 34 (threshold 15). Drivers by points: if/else 9 (28 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatOpenRouter._stream (cognitive 34) libs/partners/openrouter/langchain_openrouter/chat_models.py:592— ChatOpenRouter._stream has cognitive complexity 34 (threshold 15). Drivers by points: if/else 12 (32 pts), boolean chains 1, loops 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatOpenRouter._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatOpenRouter._astream (cognitive 34) libs/partners/openrouter/langchain_openrouter/chat_models.py:682— ChatOpenRouter._astream has cognitive complexity 34 (threshold 15). Drivers by points: if/else 12 (32 pts), boolean chains 1, loops 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatOpenRouter._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
mustache._get_key (cognitive 33) libs/core/langchain_core/utils/mustache.py:345— mustache._get_key has cognitive complexity 33 (threshold 15). Drivers by points: if/else 9 (17 pts), error handling 4 (12 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FilesystemFileSearchMiddleware._python_search (cognitive 33) libs/langchain_v1/langchain/agents/middleware/file_search.py:349— FilesystemFileSearchMiddleware._python_search has cognitive complexity 33 (threshold 15). Drivers by points: if/else 7 (22 pts), loops 3 (6 pts), error handling 2 (4 pts), boolean chains 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Chroma.add_images (cognitive 33) libs/partners/chroma/langchain_chroma/vectorstores.py:509— Chroma.add_images has cognitive complexity 33 (threshold 15). Drivers by points: if/else 11 (19 pts), ternaries 3 (8 pts), error handling 1 (3 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Chroma.add_texts (cognitive 33) libs/partners/chroma/langchain_chroma/vectorstores.py:597— Chroma.add_texts has cognitive complexity 33 (threshold 15). Drivers by points: if/else 11 (19 pts), ternaries 3 (8 pts), error handling 1 (3 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._convert_responses_chunk_to_generation_chunk (cognitive 33) libs/partners/openai/langchain_openai/chat_models/base.py:5408— base._convert_responses_chunk_to_generation_chunk has cognitive complexity 33 (threshold 15). Drivers by points: if/else 14 (21 pts), boolean chains 10, ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseOpenAI._generate (cognitive 33) libs/partners/openai/langchain_openai/llms/base.py:446— BaseOpenAI._generate has cognitive complexity 33 (threshold 15). Drivers by points: if/else 9 (23 pts), ternaries 2 (6 pts), loops 2 (4 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TextSplitter._merge_splits (cognitive 33) libs/text-splitters/langchain_text_splitters/base.py:168— TextSplitter._merge_splits has cognitive complexity 33 (threshold 15). Drivers by points: if/else 5 (13 pts), ternaries 4 (13 pts), loops 2 (5 pts), boolean chains 2 (nesting depth added 20). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
manager.handle_event (cognitive 32) libs/core/langchain_core/callbacks/manager.py:287— manager.handle_event has cognitive complexity 32 (threshold 15). Drivers by points: if/else 10 (24 pts), error handling 3 (6 pts), boolean chains 1, loops 1 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseLLM.generate (cognitive 32) libs/core/langchain_core/language_models/llms.py:852— BaseLLM.generate has cognitive complexity 32 (threshold 15). Drivers by points: boolean chains 15, if/else 11 (15 pts), ternaries 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Serializable.to_json (cognitive 32) libs/core/langchain_core/load/serializable.py:228— Serializable.to_json has cognitive complexity 32 (threshold 15). Drivers by points: if/else 8 (18 pts), loops 5 (8 pts), boolean chains 3, ternaries 2 (3 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatPerplexity._to_responses_payload (cognitive 32) libs/partners/perplexity/langchain_perplexity/chat_models.py:1047— ChatPerplexity._to_responses_payload has cognitive complexity 32 (threshold 15). Drivers by points: if/else 12 (23 pts), boolean chains 5, ternaries 1 (3 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_utils.is_openai_data_block (cognitive 31) libs/core/langchain_core/language_models/_utils.py:33— _utils.is_openai_data_block has cognitive complexity 31 (threshold 15). Drivers by points: if/else 11 (23 pts), boolean chains 8 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseLLM.agenerate (cognitive 31) libs/core/langchain_core/language_models/llms.py:1133— BaseLLM.agenerate has cognitive complexity 31 (threshold 15). Drivers by points: boolean chains 15, if/else 10 (14 pts), ternaries 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
graph_mermaid.draw_mermaid (cognitive 31) libs/core/langchain_core/runnables/graph_mermaid.py:86— graph_mermaid.draw_mermaid has cognitive complexity 31 (threshold 15). Drivers by points: if/else 10 (15 pts), loops 6 (11 pts), boolean chains 4, ternaries 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._get_builtin_translator (cognitive 31) libs/langchain/langchain_classic/retrievers/self_query/base.py:29— base._get_builtin_translator has cognitive complexity 31 (threshold 15). Drivers by points: if/else 17 (18 pts), error handling 12, boolean chains 1 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ChatAnthropic._format_output (cognitive 31) libs/partners/anthropic/langchain_anthropic/chat_models.py:2538— ChatAnthropic._format_output has cognitive complexity 31 (threshold 15). Drivers by points: if/else 12 (22 pts), boolean chains 8, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_dict_to_message (cognitive 31) libs/partners/groq/langchain_groq/chat_models.py:1532— chat_models._convert_dict_to_message has cognitive complexity 31 (threshold 15). Drivers by points: if/else 11 (19 pts), loops 2 (6 pts), error handling 1 (4 pts), boolean chains 2 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._convert_message_to_dict (cognitive 31) libs/partners/openai/langchain_openai/chat_models/base.py:476— base._convert_message_to_dict has cognitive complexity 31 (threshold 15). Drivers by points: if/else 11 (20 pts), boolean chains 6, ternaries 1 (3 pts), loops 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatOpenRouter._create_chat_result (cognitive 31) libs/partners/openrouter/langchain_openrouter/chat_models.py:827— ChatOpenRouter._create_chat_result has cognitive complexity 31 (threshold 15). Drivers by points: if/else 14 (27 pts), boolean chains 3, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatModel.astream (cognitive 30) libs/core/langchain_core/language_models/chat_models.py:901— BaseChatModel.astream has cognitive complexity 30 (threshold 15). Drivers by points: if/else 11 (20 pts), loops 2 (4 pts), boolean chains 3, ternaries 1 (2 pts), error handling 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PydanticToolsParser.parse_result (cognitive 30) libs/core/langchain_core/output_parsers/openai_tools.py:318— PydanticToolsParser.parse_result has cognitive complexity 30 (threshold 15). Drivers by points: if/else 9 (18 pts), ternaries 3 (5 pts), error handling 2 (4 pts), boolean chains 2, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnableWithFallbacks.batch (cognitive 30) libs/core/langchain_core/runnables/fallbacks.py:265— RunnableWithFallbacks.batch has cognitive complexity 30 (threshold 15). Drivers by points: if/else 10 (20 pts), boolean chains 5, loops 3 (4 pts), ternaries 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base.create_schema_from_function (cognitive 30) libs/core/langchain_core/tools/base.py:264— base.create_schema_from_function has cognitive complexity 30 (threshold 15). Drivers by points: if/else 13 (21 pts), boolean chains 5, loops 3 (4 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
function_calling.convert_to_openai_function (cognitive 30) libs/core/langchain_core/utils/function_calling.py:377— function_calling.convert_to_openai_function has cognitive complexity 30 (threshold 15). Drivers by points: if/else 12 (20 pts), boolean chains 10 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HumanInTheLoopMiddleware.after_model (cognitive 30) libs/langchain_v1/langchain/agents/middleware/human_in_the_loop.py:760— HumanInTheLoopMiddleware.after_model has cognitive complexity 30 (threshold 15). Drivers by points: if/else 14 (26 pts), boolean chains 2, loops 2 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatAnthropic.bind_tools (cognitive 30) libs/partners/anthropic/langchain_anthropic/chat_models.py:2684— ChatAnthropic.bind_tools has cognitive complexity 30 (threshold 15). Drivers by points: if/else 14 (23 pts), boolean chains 6, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_message_to_dict (cognitive 30) libs/partners/groq/langchain_groq/chat_models.py:1375— chat_models._convert_message_to_dict has cognitive complexity 30 (threshold 15). Drivers by points: if/else 11 (23 pts), boolean chains 7 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AzureChatOpenAI.validate_environment (cognitive 30) libs/partners/openai/langchain_openai/chat_models/azure.py:627— AzureChatOpenAI.validate_environment has cognitive complexity 30 (threshold 15). Drivers by points: if/else 15 (19 pts), boolean chains 9, ternaries 2 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
BaseChatOpenAI.validate_environment (cognitive 30) libs/partners/openai/langchain_openai/chat_models/base.py:1408— BaseChatOpenAI.validate_environment has cognitive complexity 30 (threshold 15). Drivers by points: if/else 14 (18 pts), boolean chains 12 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
BaseChatOpenAI.bind_tools (cognitive 30) libs/partners/openai/langchain_openai/chat_models/base.py:2511— BaseChatOpenAI.bind_tools has cognitive complexity 30 (threshold 15). Drivers by points: if/else 13 (22 pts), loops 3 (5 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIEmbeddings._tokenize (cognitive 30) libs/partners/openai/langchain_openai/embeddings/base.py:476— OpenAIEmbeddings._tokenize has cognitive complexity 30 (threshold 15). Drivers by points: if/else 8 (13 pts), loops 4 (10 pts), error handling 3 (6 pts), boolean chains 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
anthropic._convert_citation_to_v1 (cognitive 29) libs/core/langchain_core/messages/block_translators/anthropic.py:166— anthropic._convert_citation_to_v1 has cognitive complexity 29 (threshold 15). Drivers by points: if/else 10 (24 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Reviver.__call__ (cognitive 28) libs/core/langchain_core/load/load.py:460— Reviver.__call__ has cognitive complexity 28 (threshold 15). Drivers by points: if/else 13 (22 pts), boolean chains 6 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AIMessage.content_blocks (cognitive 28) libs/core/langchain_core/messages/ai.py:243— AIMessage.content_blocks has cognitive complexity 28 (threshold 15). Drivers by points: if/else 9 (19 pts), boolean chains 4, error handling 1 (3 pts), loops 1 (2 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AIMessageChunk.init_tool_calls (cognitive 28) libs/core/langchain_core/messages/ai.py:509— AIMessageChunk.init_tool_calls has cognitive complexity 28 (threshold 15). Drivers by points: if/else 9 (18 pts), boolean chains 3, loops 2 (3 pts), error handling 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils._create_message_from_message_type (cognitive 28) REDACTED:606— utils._create_message_from_message_type has cognitive complexity 28 (threshold 15). Drivers by points: if/else 15 (25 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnableWithFallbacks.abatch (cognitive 28) libs/core/langchain_core/runnables/fallbacks.py:361— RunnableWithFallbacks.abatch has cognitive complexity 28 (threshold 15). Drivers by points: if/else 10 (20 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatOllama.with_structured_output (cognitive 28) libs/partners/ollama/langchain_ollama/chat_models.py:1444— ChatOllama.with_structured_output has cognitive complexity 28 (threshold 15). Drivers by points: if/else 15 (26 pts), ternaries 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._stream (cognitive 28) libs/partners/openai/langchain_openai/chat_models/base.py:1867— BaseChatOpenAI._stream has cognitive complexity 28 (threshold 15). Drivers by points: if/else 12 (20 pts), boolean chains 3, error handling 2, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatOpenAI._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatOpenAI._astream (cognitive 28) libs/partners/openai/langchain_openai/chat_models/base.py:2163— BaseChatOpenAI._astream has cognitive complexity 28 (threshold 15). Drivers by points: if/else 12 (20 pts), boolean chains 3, error handling 2, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatOpenAI._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
base._format_message_content (cognitive 28) libs/partners/openai/langchain_openai/chat_models/base.py:385— base._format_message_content has cognitive complexity 28 (threshold 15). Drivers by points: if/else 8 (15 pts), boolean chains 11, loops 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
check_diff.dependents_graph (cognitive 28) .github/scripts/check_diff.py:64— check_diff.dependents_graph has cognitive complexity 28 (threshold 15). Drivers by points: if/else 7 (19 pts), loops 5 (9 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat_bridge.chunks_to_events (cognitive 27) libs/core/langchain_core/language_models/_compat_bridge.py:586— _compat_bridge.chunks_to_events has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (20 pts), loops 3 (4 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (_compat_bridge.achunks_to_events) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_compat_bridge.achunks_to_events (cognitive 27) libs/core/langchain_core/language_models/_compat_bridge.py:692— _compat_bridge.achunks_to_events has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (20 pts), loops 3 (4 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (_compat_bridge.chunks_to_events) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_AsyncProjectionIterator.__anext__ (cognitive 27) libs/core/langchain_core/language_models/chat_model_stream.py:454— _AsyncProjectionIterator.__anext__ has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (21 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._convert_openai_format_to_data_block (cognitive 27) libs/core/langchain_core/messages/block_translators/openai.py:429— openai._convert_openai_format_to_data_block has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (13 pts), loops 5 (10 pts), boolean chains 4 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._convert_annotation_to_v1 (cognitive 27) libs/core/langchain_core/messages/block_translators/openai.py:565— openai._convert_annotation_to_v1 has cognitive complexity 27 (threshold 15). Drivers by points: if/else 8 (21 pts), loops 3 (6 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._init_chat_model_helper (cognitive 27) libs/langchain/langchain_classic/chat_models/base.py:389— base._init_chat_model_helper has cognitive complexity 27 (threshold 15). Drivers by points: if/else 22, error handling 2 (5 pts) (nesting depth added 3). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
_EmbeddingDistanceChainMixin._cosine_distance (cognitive 27) libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:193— _EmbeddingDistanceChainMixin._cosine_distance has cognitive complexity 27 (threshold 15). Drivers by points: if/else 5 (16 pts), ternaries 2 (6 pts), error handling 2 (3 pts), boolean chains 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._format_data_content_block (cognitive 27) libs/partners/anthropic/langchain_anthropic/chat_models.py:393— chat_models._format_data_content_block has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (16 pts), boolean chains 9, loops 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatOllama._iterate_over_stream (cognitive 27) libs/partners/ollama/langchain_ollama/chat_models.py:1228— ChatOllama._iterate_over_stream has cognitive complexity 27 (threshold 15). Drivers by points: if/else 6 (16 pts), ternaries 2 (7 pts), boolean chains 3, loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatOllama._aiterate_over_stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatOllama._aiterate_over_stream (cognitive 27) libs/partners/ollama/langchain_ollama/chat_models.py:1310— ChatOllama._aiterate_over_stream has cognitive complexity 27 (threshold 15). Drivers by points: if/else 6 (16 pts), ternaries 2 (7 pts), boolean chains 3, loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatOllama._iterate_over_stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatOpenAI.with_structured_output (cognitive 27) libs/partners/openai/langchain_openai/chat_models/base.py:2620— BaseChatOpenAI.with_structured_output has cognitive complexity 27 (threshold 15). Drivers by points: if/else 14 (21 pts), boolean chains 4, ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseOpenAI._agenerate (cognitive 27) libs/partners/openai/langchain_openai/llms/base.py:530— BaseOpenAI._agenerate has cognitive complexity 27 (threshold 15). Drivers by points: if/else 7 (17 pts), ternaries 2 (6 pts), loops 2 (4 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_message_to_dict (cognitive 27) libs/partners/openrouter/langchain_openrouter/chat_models.py:1271— chat_models._convert_message_to_dict has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (20 pts), boolean chains 7 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RecursiveCharacterTextSplitter.get_separators_for_language (cognitive 27) libs/text-splitters/langchain_text_splitters/character.py:183— RecursiveCharacterTextSplitter.get_separators_for_language has cognitive complexity 27 (threshold 15). Drivers by points: if/else 27. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
JsonOutputKeyToolsParser.parse_result (cognitive 26) libs/core/langchain_core/output_parsers/openai_tools.py:233— JsonOutputKeyToolsParser.parse_result has cognitive complexity 26 (threshold 15). Drivers by points: if/else 10 (16 pts), loops 2 (3 pts), ternaries 2 (3 pts), boolean chains 2, error handling 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnableRetry._batch (cognitive 26) libs/core/langchain_core/runnables/retry.py:234— RunnableRetry._batch has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (20 pts), loops 3 (4 pts), boolean chains 1, error handling 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableRetry._abatch) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
RunnableRetry._abatch (cognitive 26) libs/core/langchain_core/runnables/retry.py:310— RunnableRetry._abatch has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (20 pts), loops 3 (4 pts), boolean chains 1, error handling 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableRetry._batch) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
utils.get_function_nonlocals (cognitive 26) libs/core/langchain_core/runnables/utils.py:412— utils.get_function_nonlocals has cognitive complexity 26 (threshold 15). Drivers by points: if/else 3 (10 pts), loops 3 (7 pts), error handling 2 (6 pts), boolean chains 2, ternaries 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sys_info.print_sys_info (cognitive 26) libs/core/langchain_core/sys_info.py:36— sys_info.print_sys_info has cognitive complexity 26 (threshold 15). Drivers by points: if/else 8 (13 pts), error handling 3 (7 pts), loops 4 (6 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
function_calling._convert_any_typed_dicts_to_pydantic (cognitive 26) libs/core/langchain_core/utils/function_calling.py:259— function_calling._convert_any_typed_dicts_to_pydantic has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (20 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (2 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_responses_to_chat_result (cognitive 26) libs/partners/perplexity/langchain_perplexity/chat_models.py:402— chat_models._convert_responses_to_chat_result has cognitive complexity 26 (threshold 15). Drivers by points: if/else 4 (9 pts), ternaries 2 (7 pts), boolean chains 4, error handling 1 (3 pts), loops 3 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
get_min_versions.get_min_version_from_toml (cognitive 26) .github/scripts/get_min_versions.py:115— get_min_versions.get_min_version_from_toml has cognitive complexity 26 (threshold 15). Drivers by points: if/else 5 (14 pts), loops 5 (8 pts), boolean chains 4 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseTool.arun (cognitive 25) libs/core/langchain_core/tools/base.py:1138— BaseTool.arun has cognitive complexity 25 (threshold 15). Drivers by points: if/else 11 (14 pts), error handling 4 (6 pts), ternaries 4, boolean chains 1 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
json.parse_partial_json (cognitive 25) libs/core/langchain_core/utils/json.py:60— json.parse_partial_json has cognitive complexity 25 (threshold 15). Drivers by points: if/else 9 (17 pts), boolean chains 3, error handling 2 (3 pts), loops 2 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._collect_code_execution_tool_ids (cognitive 25) libs/partners/anthropic/langchain_anthropic/chat_models.py:1093— chat_models._collect_code_execution_tool_ids has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (22 pts), loops 2 (3 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._format_message_content (cognitive 25) REDACTED:296— chat_models._format_message_content has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (20 pts), boolean chains 4, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatHuggingFace._stream (cognitive 25) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:828— ChatHuggingFace._stream has cognitive complexity 25 (threshold 15). Drivers by points: if/else 8 (20 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._convert_dict_to_message (cognitive 25) libs/partners/openai/langchain_openai/chat_models/base.py:220— base._convert_dict_to_message has cognitive complexity 25 (threshold 15). Drivers by points: if/else 10 (15 pts), error handling 1 (4 pts), loops 1 (3 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._translate_responses_input (cognitive 25) libs/partners/perplexity/langchain_perplexity/chat_models.py:217— chat_models._translate_responses_input has cognitive complexity 25 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 2 (4 pts), boolean chains 3, ternaries 1 (3 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
deprecation.warn_deprecated (cognitive 24) libs/core/langchain_core/_api/deprecation.py:479— deprecation.warn_deprecated has cognitive complexity 24 (threshold 15). Drivers by points: if/else 11 (19 pts), ternaries 2 (3 pts), boolean chains 2 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_ChatModelStreamBase._push_content_block_finish (cognitive 24) libs/core/langchain_core/language_models/chat_model_stream.py:941— _ChatModelStreamBase._push_content_block_finish has cognitive complexity 24 (threshold 15). Drivers by points: if/else 11 (19 pts), boolean chains 5 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._generate_response_from_error (cognitive 24) libs/core/langchain_core/language_models/chat_models.py:112— chat_models._generate_response_from_error has cognitive complexity 24 (threshold 15). Drivers by points: if/else 7 (13 pts), error handling 3 (10 pts), boolean chains 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseTool.run (cognitive 24) libs/core/langchain_core/tools/base.py:1010— BaseTool.run has cognitive complexity 24 (threshold 15). Drivers by points: if/else 11 (14 pts), error handling 4 (6 pts), ternaries 3, boolean chains 1 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
base.get_all_basemodel_annotations (cognitive 24) libs/core/langchain_core/tools/base.py:1831— base.get_all_basemodel_annotations has cognitive complexity 24 (threshold 15). Drivers by points: if/else 7 (14 pts), loops 3 (7 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
html.extract_sub_links (cognitive 24) libs/core/langchain_core/utils/html.py:62— html.extract_sub_links has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (19 pts), error handling 1 (2 pts), loops 2, ternaries 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClearToolUsesEdit.apply (cognitive 24) libs/langchain_v1/langchain/agents/middleware/context_editing.py:79— ClearToolUsesEdit.apply has cognitive complexity 24 (threshold 15). Drivers by points: if/else 12 (22 pts), boolean chains 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatAnthropic._assert_valid_model_configuration (cognitive 24) libs/partners/anthropic/langchain_anthropic/chat_models.py:1804— ChatAnthropic._assert_valid_model_configuration has cognitive complexity 24 (threshold 15). Drivers by points: if/else 12 (16 pts), boolean chains 8 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicLLM._format_messages (cognitive 24) libs/partners/anthropic/langchain_anthropic/llms.py:200— AnthropicLLM._format_messages has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (19 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatFireworks._combine_llm_outputs (cognitive 24) REDACTED:1343— ChatFireworks._combine_llm_outputs has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (18 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._generate (cognitive 24) libs/partners/openai/langchain_openai/chat_models/base.py:1944— BaseChatOpenAI._generate has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 6, error handling 3, loops 1 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._create_chat_result (cognitive 24) libs/partners/openai/langchain_openai/chat_models/base.py:2066— BaseChatOpenAI._create_chat_result has cognitive complexity 24 (threshold 15). Drivers by points: if/else 11 (16 pts), boolean chains 3, ternaries 2 (3 pts), error handling 1, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIEmbeddings.validate_environment (cognitive 24) libs/partners/openai/langchain_openai/embeddings/base.py:377— OpenAIEmbeddings.validate_environment has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (13 pts), error handling 2 (7 pts), boolean chains 4 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatPromptTemplate.validate_input_variables (cognitive 23) libs/core/langchain_core/prompts/chat.py:1054— ChatPromptTemplate.validate_input_variables has cognitive complexity 23 (threshold 15). Drivers by points: if/else 11 (20 pts), boolean chains 2, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
NonLocals.visit_Attribute (cognitive 23) libs/core/langchain_core/runnables/utils.py:277— NonLocals.visit_Attribute has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (17 pts), loops 2 (6 pts) (nesting depth added 14). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
OpenAIAssistantRunnable._get_response (cognitive 23) libs/langchain/langchain_classic/agents/openai_assistant/base.py:592— OpenAIAssistantRunnable._get_response has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 3, error handling 1 (3 pts), loops 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (OpenAIAssistantRunnable._aget_response) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
OpenAIAssistantRunnable._aget_response (cognitive 23) libs/langchain/langchain_classic/agents/openai_assistant/base.py:749— OpenAIAssistantRunnable._aget_response has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 3, error handling 1 (3 pts), loops 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (OpenAIAssistantRunnable._get_response) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
openapi._format_url (cognitive 23) libs/langchain/langchain_classic/chains/openai_functions/openapi.py:37— openapi._format_url has cognitive complexity 23 (threshold 15). Drivers by points: if/else 6 (11 pts), ternaries 3 (11 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StateFileSearchMiddleware._handle_grep_search (cognitive 23) libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:263— StateFileSearchMiddleware._handle_grep_search has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (16 pts), loops 2 (3 pts), boolean chains 2, error handling 1, ternaries 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_dict_to_message (cognitive 23) REDACTED:140— chat_models._convert_dict_to_message has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (13 pts), error handling 1 (4 pts), boolean chains 3, loops 1 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatGroq._stream (cognitive 23) libs/partners/groq/langchain_groq/chat_models.py:712— ChatGroq._stream has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (18 pts), boolean chains 3, error handling 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatGroq._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatGroq._astream (cognitive 23) libs/partners/groq/langchain_groq/chat_models.py:768— ChatGroq._astream has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (18 pts), boolean chains 3, error handling 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatGroq._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
huggingface._convert_chunk_to_message_chunk (cognitive 23) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:250— huggingface._convert_chunk_to_message_chunk has cognitive complexity 23 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 8, loops 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
_compat._implode_reasoning_blocks (cognitive 23) libs/partners/openai/langchain_openai/chat_models/_compat.py:241— _compat._implode_reasoning_blocks has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (17 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._stream_responses (cognitive 23) libs/partners/openai/langchain_openai/chat_models/base.py:1703— BaseChatOpenAI._stream_responses has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (15 pts), boolean chains 3, error handling 2, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatOpenAI._astream_responses) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
BaseChatOpenAI._astream_responses (cognitive 23) libs/partners/openai/langchain_openai/chat_models/base.py:1772— BaseChatOpenAI._astream_responses has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (15 pts), boolean chains 3, error handling 2, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (BaseChatOpenAI._stream_responses) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
base._convert_delta_to_message_chunk (cognitive 23) libs/partners/openai/langchain_openai/chat_models/base.py:558— base._convert_delta_to_message_chunk has cognitive complexity 23 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 8, error handling 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
chat._create_template_from_message_type (cognitive 22) libs/core/langchain_core/prompts/chat.py:1342— chat._create_template_from_message_type has cognitive complexity 22 (threshold 15). Drivers by points: if/else 8 (17 pts), error handling 1 (3 pts), boolean chains 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
config.ensure_config (cognitive 22) libs/core/langchain_core/runnables/config.py:255— config.ensure_config has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (12 pts), ternaries 2 (4 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AgentExecutor._iter_next_step (cognitive 22) libs/langchain/langchain_classic/agents/agent.py:1301— AgentExecutor._iter_next_step has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (15 pts), ternaries 3 (4 pts), loops 2, error handling 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ShellSession._collect_output (cognitive 22) libs/langchain_v1/langchain/agents/middleware/shell_tool.py:240— ShellSession._collect_output has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (17 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._convert_message_to_dict (cognitive 22) REDACTED:369— chat_models._convert_message_to_dict has cognitive complexity 22 (threshold 15). Drivers by points: if/else 11 (19 pts), boolean chains 3 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatHuggingFace._inherit_llm_properties (cognitive 22) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:540— ChatHuggingFace._inherit_llm_properties has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (15 pts), boolean chains 4, loops 2 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._convert_annotation_from_v1 (cognitive 22) libs/partners/openai/langchain_openai/chat_models/_compat.py:197— _compat._convert_annotation_from_v1 has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (20 pts), loops 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._agenerate (cognitive 22) libs/partners/openai/langchain_openai/chat_models/base.py:2245— BaseChatOpenAI._agenerate has cognitive complexity 22 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 4, error handling 3, loops 1 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AzureOpenAI.validate_environment (cognitive 22) libs/partners/openai/langchain_openai/llms/azure.py:127— AzureOpenAI.validate_environment has cognitive complexity 22 (threshold 15). Drivers by points: if/else 10 (13 pts), boolean chains 7, ternaries 2 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
ChatPerplexity._generate (cognitive 22) libs/partners/perplexity/langchain_perplexity/chat_models.py:1433— ChatPerplexity._generate has cognitive complexity 22 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 4, ternaries 2 (4 pts), loops 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level. This shape REPEATS in the file: one other method here (ChatPerplexity._agenerate) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatPerplexity._agenerate (cognitive 22) libs/partners/perplexity/langchain_perplexity/chat_models.py:1500— ChatPerplexity._agenerate has cognitive complexity 22 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 4, ternaries 2 (4 pts), loops 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level. This shape REPEATS in the file: one other method here (ChatPerplexity._generate) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
utils.trim_messages (cognitive 21) REDACTED:1146— utils.trim_messages has cognitive complexity 21 (threshold 15). Drivers by points: if/else 14 (16 pts), boolean chains 3, ternaries 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
_StreamingParser.parse (cognitive 21) REDACTED:81— _StreamingParser.parse has cognitive complexity 21 (threshold 15). Drivers by points: if/else 11 (19 pts), error handling 1, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._get_injected_args_keys_from_signature (cognitive 21) libs/core/langchain_core/tools/base.py:1618— base._get_injected_args_keys_from_signature has cognitive complexity 21 (threshold 15). Drivers by points: if/else 6 (14 pts), ternaries 2 (5 pts), boolean chains 1, loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_TracerCore._complete_llm_run (cognitive 21) libs/core/langchain_core/tracers/core.py:328— _TracerCore._complete_llm_run has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (14 pts), loops 4 (6 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_gateway._resolve_gateway_config (cognitive 21) libs/core/langchain_core/utils/_gateway.py:186— _gateway._resolve_gateway_config has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (12 pts), ternaries 3 (6 pts), boolean chains 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_merge.merge_dicts (cognitive 21) libs/core/langchain_core/utils/_merge.py:6— _merge.merge_dicts has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (13 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
mustache.tokenize (cognitive 21) libs/core/langchain_core/utils/mustache.py:199— mustache.tokenize has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (17 pts), error handling 1 (3 pts), loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base.fix_filter_directive (cognitive 21) libs/langchain/langchain_classic/chains/query_constructor/base.py:114— base.fix_filter_directive has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (15 pts), boolean chains 6 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatGroq.with_structured_output (cognitive 21) libs/partners/groq/langchain_groq/chat_models.py:971— ChatGroq.with_structured_output has cognitive complexity 21 (threshold 15). Drivers by points: if/else 10 (16 pts), ternaries 2 (4 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OllamaLLM._astream_with_aggregation (cognitive 21) libs/partners/ollama/langchain_ollama/llms.py:383— OllamaLLM._astream_with_aggregation has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (17 pts), ternaries 1 (3 pts), loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (OllamaLLM._stream_with_aggregation) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
OllamaLLM._stream_with_aggregation (cognitive 21) libs/partners/ollama/langchain_ollama/llms.py:425— OllamaLLM._stream_with_aggregation has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (17 pts), ternaries 1 (3 pts), loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (OllamaLLM._astream_with_aggregation) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
chat_models._convert_dict_to_message (cognitive 21) libs/partners/openrouter/langchain_openrouter/chat_models.py:1347— chat_models._convert_dict_to_message has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (13 pts), error handling 1 (4 pts), loops 1 (3 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Qdrant.construct_instance (cognitive 21) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1614— Qdrant.construct_instance has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (16 pts), boolean chains 5 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (Qdrant.aconstruct_instance) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
Qdrant.aconstruct_instance (cognitive 21) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1779— Qdrant.aconstruct_instance has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (16 pts), boolean chains 5 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (Qdrant.construct_instance) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
client._parse_retry_after (cognitive 21) libs/partners/typesafe/langchain_typesafe/client.py:231— client._parse_retry_after has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (12 pts), error handling 2 (6 pts), boolean chains 2, loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RecursiveCharacterTextSplitter._split_text (cognitive 21) libs/text-splitters/langchain_text_splitters/character.py:110— RecursiveCharacterTextSplitter._split_text has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (15 pts), ternaries 3 (4 pts), loops 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SyncProjection.__iter__ (cognitive 20) libs/core/langchain_core/language_models/chat_model_stream.py:247— SyncProjection.__iter__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ChatModelStream.__iter__) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatModelStream.__iter__ (cognitive 20) libs/core/langchain_core/language_models/chat_model_stream.py:1303— ChatModelStream.__iter__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (SyncProjection.__iter__) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ChatGeneration.set_text (cognitive 20) libs/core/langchain_core/outputs/chat_generation.py:45— ChatGeneration.set_text has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (14 pts), boolean chains 3, loops 1 (3 pts) (nesting depth added 10). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
graph_mermaid._render_mermaid_using_api (cognitive 20) libs/core/langchain_core/runnables/graph_mermaid.py:445— graph_mermaid._render_mermaid_using_api has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (15 pts), error handling 1 (2 pts), boolean chains 1, loops 1, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnablePassthrough.atransform (cognitive 20) libs/core/langchain_core/runnables/passthrough.py:284— RunnablePassthrough.atransform has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (11 pts), error handling 1 (4 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StructuredTool.from_function (cognitive 20) libs/core/langchain_core/tools/structured.py:188— StructuredTool.from_function has cognitive complexity 20 (threshold 15). Drivers by points: if/else 10 (13 pts), boolean chains 7 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
AgentExecutor._aiter_next_step (cognitive 20) libs/langchain/langchain_classic/agents/agent.py:1440— AgentExecutor._aiter_next_step has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (13 pts), ternaries 3 (4 pts), loops 2, error handling 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PandasDataFrameOutputParser.parse (cognitive 20) libs/langchain/langchain_classic/output_parsers/pandas_dataframe.py:93— PandasDataFrameOutputParser.parse has cognitive complexity 20 (threshold 15). Drivers by points: if/else 11 (17 pts), ternaries 1 (2 pts), error handling 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models.convert_to_anthropic_tool (cognitive 20) libs/partners/anthropic/langchain_anthropic/chat_models.py:3208— chat_models.convert_to_anthropic_tool has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 4, loops 1 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
huggingface._convert_dict_to_message (cognitive 20) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:185— huggingface._convert_dict_to_message has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (11 pts), error handling 1 (4 pts), loops 1 (3 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._combine_llm_outputs (cognitive 20) libs/partners/openai/langchain_openai/chat_models/base.py:1597— BaseChatOpenAI._combine_llm_outputs has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (16 pts), loops 2 (4 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseChatOpenAI._convert_chunk_to_generation_chunk (cognitive 20) libs/partners/openai/langchain_openai/chat_models/base.py:1622— BaseChatOpenAI._convert_chunk_to_generation_chunk has cognitive complexity 20 (threshold 15). Drivers by points: if/else 11 (15 pts), boolean chains 3, ternaries 2 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
_classifier_input._without_media (cognitive 20) libs/partners/openai/langchain_openai/decisions/_classifier_input.py:81— _classifier_input._without_media has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (13 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AIMessageChunk.content_blocks (cognitive 19) libs/core/langchain_core/messages/ai.py:446— AIMessageChunk.content_blocks has cognitive complexity 19 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 3, error handling 1 (3 pts), loops 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utils._convert_to_message (cognitive 19) REDACTED:719— utils._convert_to_message has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 3 (7 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ListOutputParser._transform (cognitive 19) libs/core/langchain_core/output_parsers/list.py:73— ListOutputParser._transform has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (9 pts), loops 4 (8 pts), error handling 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ListOutputParser._atransform) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ListOutputParser._atransform (cognitive 19) libs/core/langchain_core/output_parsers/list.py:105— ListOutputParser._atransform has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (9 pts), loops 4 (8 pts), error handling 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ListOutputParser._transform) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
RunnableWithFallbacks.stream (cognitive 19) libs/core/langchain_core/runnables/fallbacks.py:465— RunnableWithFallbacks.stream has cognitive complexity 19 (threshold 15). Drivers by points: error handling 4 (7 pts), if/else 3 (4 pts), boolean chains 3, ternaries 1 (3 pts), loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableWithFallbacks.astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
RunnableWithFallbacks.astream (cognitive 19) libs/core/langchain_core/runnables/fallbacks.py:529— RunnableWithFallbacks.astream has cognitive complexity 19 (threshold 15). Drivers by points: error handling 4 (7 pts), if/else 3 (4 pts), boolean chains 3, ternaries 1 (3 pts), loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (RunnableWithFallbacks.stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
AsciiCanvas.line (cognitive 19) libs/core/langchain_core/runnables/graph_ascii.py:117— AsciiCanvas.line has cognitive complexity 19 (threshold 15). Drivers by points: ternaries 3 (9 pts), loops 3 (6 pts), if/else 3, boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._parse_ai_message (cognitive 19) libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:37— base._parse_ai_message has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 2 (4 pts), ternaries 1 (3 pts), loops 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_DatasetRunContainer._collect_metrics (cognitive 19) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1218— _DatasetRunContainer._collect_metrics has cognitive complexity 19 (threshold 15). Drivers by points: ternaries 2 (8 pts), loops 3 (7 pts), if/else 1 (3 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
factory._resolve_schema (cognitive 19) libs/langchain_v1/langchain/agents/factory.py:492— factory._resolve_schema has cognitive complexity 19 (threshold 15). Drivers by points: if/else 3 (11 pts), loops 3 (7 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ShellSession._collect_output_after_exit (cognitive 19) libs/langchain_v1/langchain/agents/middleware/shell_tool.py:327— ShellSession._collect_output_after_exit has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (15 pts), error handling 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
experimental._xml_to_function_call (cognitive 19) libs/partners/anthropic/langchain_anthropic/experimental.py:103— experimental._xml_to_function_call has cognitive complexity 19 (threshold 15). Drivers by points: if/else 5 (13 pts), boolean chains 4, loops 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat_bridge._iter_protocol_blocks (cognitive 18) libs/core/langchain_core/language_models/_compat_bridge.py:118— _compat_bridge._iter_protocol_blocks has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (10 pts), loops 3 (6 pts), boolean chains 1, error handling 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat_bridge._start_skeleton (cognitive 18) libs/core/langchain_core/language_models/_compat_bridge.py:204— _compat_bridge._start_skeleton has cognitive complexity 18 (threshold 15). Drivers by points: if/else 12 (18 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ai.add_ai_message_chunks (cognitive 18) libs/core/langchain_core/messages/ai.py:651— ai.add_ai_message_chunks has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (10 pts), loops 2 (3 pts), ternaries 2 (3 pts), boolean chains 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SequentialChain.validate_chains (cognitive 18) libs/langchain/langchain_classic/chains/sequential.py:40— SequentialChain.validate_chains has cognitive complexity 18 (threshold 15). Drivers by points: if/else 10 (16 pts), boolean chains 1, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_PIIStreamTransformer._process_tools_event (cognitive 18) libs/langchain_v1/langchain/agents/middleware/pii.py:154— _PIIStreamTransformer._process_tools_event has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (15 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
provider_tool_search._get_model_provider (cognitive 18) libs/langchain_v1/langchain/agents/middleware/provider_tool_search.py:234— provider_tool_search._get_model_provider has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 3, ternaries 1 (3 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolRetryMiddleware.wrap_tool_call (cognitive 18) libs/langchain_v1/langchain/agents/middleware/tool_retry.py:295— ToolRetryMiddleware.wrap_tool_call has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (12 pts), error handling 2 (4 pts), loops 1, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ToolRetryMiddleware.awrap_tool_call) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ToolRetryMiddleware.awrap_tool_call (cognitive 18) libs/langchain_v1/langchain/agents/middleware/tool_retry.py:359— ToolRetryMiddleware.awrap_tool_call has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (12 pts), error handling 2 (4 pts), loops 1, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ToolRetryMiddleware.wrap_tool_call) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
tools._convert_content_block (cognitive 18) libs/langchain_v1/langchain/mcp/tools.py:120— tools._convert_content_block has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (14 pts), boolean chains 4 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_summary.summarize (cognitive 18) libs/model-profiles/langchain_model_profiles/_summary.py:416— _summary.summarize has cognitive complexity 18 (threshold 15). Drivers by points: error handling 4 (9 pts), if/else 3 (5 pts), boolean chains 3, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_models._parse_arguments_from_tool_call (cognitive 18) libs/partners/ollama/langchain_ollama/chat_models.py:172— chat_models._parse_arguments_from_tool_call has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (15 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AzureOpenAIEmbeddings.validate_environment (cognitive 18) libs/partners/openai/langchain_openai/embeddings/azure.py:162— AzureOpenAIEmbeddings.validate_environment has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (10 pts), boolean chains 6, ternaries 2 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AIMessageChunk.init_server_tool_calls (cognitive 17) libs/core/langchain_core/messages/ai.py:604— AIMessageChunk.init_server_tool_calls has cognitive complexity 17 (threshold 15). Drivers by points: if/else 3 (8 pts), error handling 1 (4 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._explode_reasoning (cognitive 17) libs/core/langchain_core/messages/block_translators/openai.py:618— openai._explode_reasoning has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (13 pts), boolean chains 2, loops 2 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
string.mustache_schema (cognitive 17) libs/core/langchain_core/prompts/string.py:158— string.mustache_schema has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (9 pts), loops 4 (5 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
graph_ascii.draw_ascii (cognitive 17) libs/core/langchain_core/runnables/graph_ascii.py:247— graph_ascii.draw_ascii has cognitive complexity 17 (threshold 15). Drivers by points: loops 6 (8 pts), if/else 2 (5 pts), ternaries 1 (3 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LogStreamCallbackHandler.include_run (cognitive 17) libs/core/langchain_core/tracers/log_stream.py:387— LogStreamCallbackHandler.include_run has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9, boolean chains 8. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
aiter.tee_peer (cognitive 17) libs/core/langchain_core/utils/aiter.py:103— aiter.tee_peer has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), loops 3 (5 pts), error handling 1 (3 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
iter.tee_peer (cognitive 17) libs/core/langchain_core/utils/iter.py:35— iter.tee_peer has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), loops 3 (5 pts), error handling 1 (3 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AgentExecutorIterator.__aiter__ (cognitive 17) libs/langchain/langchain_classic/agents/agent_iterator.py:236— AgentExecutorIterator.__aiter__ has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 2 (3 pts), error handling 2, boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
model_fallback._sanitize_request_for_fallback (cognitive 17) libs/langchain_v1/langchain/agents/middleware/model_fallback.py:113— model_fallback._sanitize_request_for_fallback has cognitive complexity 17 (threshold 15). Drivers by points: if/else 10 (14 pts), boolean chains 3 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SummarizationMiddleware._find_token_based_cutoff (cognitive 17) libs/langchain_v1/langchain/agents/middleware/summarization.py:752— SummarizationMiddleware._find_token_based_cutoff has cognitive complexity 17 (threshold 15). Drivers by points: if/else 12 (16 pts), loops 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatAnthropic.with_structured_output (cognitive 17) libs/partners/anthropic/langchain_anthropic/chat_models.py:2889— ChatAnthropic.with_structured_output has cognitive complexity 17 (threshold 15). Drivers by points: if/else 10 (13 pts), boolean chains 4 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
chat_models._create_usage_metadata (cognitive 17) libs/partners/anthropic/langchain_anthropic/chat_models.py:3340— chat_models._create_usage_metadata has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (10 pts), boolean chains 5, loops 1 (2 pts) (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_compat._convert_from_v1_to_chat_completions (cognitive 17) libs/partners/openai/langchain_openai/chat_models/_compat.py:169— _compat._convert_from_v1_to_chat_completions has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 1 (2 pts) (nesting depth added 10). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
codex._maybe_has_system_messages (cognitive 17) libs/partners/openai/langchain_openai/chat_models/codex.py:93— codex._maybe_has_system_messages has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatPerplexity._default_params (cognitive 17) libs/partners/perplexity/langchain_perplexity/chat_models.py:933— ChatPerplexity._default_params has cognitive complexity 17 (threshold 15). Drivers by points: if/else 16 (17 pts) (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
BaseChatModel.agenerate (cognitive 16) libs/core/langchain_core/language_models/chat_models.py:1761— BaseChatModel.agenerate has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 2, loops 1, ternaries 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseLLM.stream (cognitive 16) libs/core/langchain_core/language_models/llms.py:514— BaseLLM.stream has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (8 pts), ternaries 1 (3 pts), error handling 1 (2 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AIMessage._backwards_compat_tool_calls (cognitive 16) libs/core/langchain_core/messages/ai.py:309— AIMessage._backwards_compat_tool_calls has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (13 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
google_genai.translate_grounding_metadata_to_citations (cognitive 16) libs/core/langchain_core/messages/block_translators/google_genai.py:25— google_genai.translate_grounding_metadata_to_citations has cognitive complexity 16 (threshold 15). Drivers by points: if/else 3 (8 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
content.is_data_content_block (cognitive 16) libs/core/langchain_core/messages/content.py:937— content.is_data_content_block has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (9 pts), boolean chains 7 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
JsonOutputFunctionsParser.parse_result (cognitive 16) libs/core/langchain_core/output_parsers/openai_functions.py:80— JsonOutputFunctionsParser.parse_result has cognitive complexity 16 (threshold 15). Drivers by points: error handling 5 (8 pts), if/else 6 (8 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
dict._insert_input_variables (cognitive 16) libs/core/langchain_core/prompts/dict.py:143— dict._insert_input_variables has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (11 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Runnable._batch_with_config (cognitive 16) libs/core/langchain_core/runnables/base.py:2415— Runnable._batch_with_config has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (9 pts), boolean chains 3, loops 2 (3 pts), error handling 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
RunnableLambda.get_graph (cognitive 16) libs/core/langchain_core/runnables/base.py:5119— RunnableLambda.get_graph has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (14 pts), loops 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RunnablePassthrough.transform (cognitive 16) libs/core/langchain_core/runnables/passthrough.py:253— RunnablePassthrough.transform has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (8 pts), error handling 1 (4 pts), loops 2 (4 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_RootEventFilter.include_event (cognitive 16) libs/core/langchain_core/runnables/utils.py:736— _RootEventFilter.include_event has cognitive complexity 16 (threshold 15). Drivers by points: boolean chains 8, if/else 8. To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
AgentExecutorIterator.__iter__ (cognitive 16) libs/langchain/langchain_classic/agents/agent_iterator.py:172— AgentExecutorIterator.__iter__ has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 2 (3 pts), boolean chains 1, error handling 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openapi.get_openapi_chain (cognitive 16) libs/langchain/langchain_classic/chains/openai_functions/openapi.py:275— openapi.get_openapi_chain has cognitive complexity 16 (threshold 15). Drivers by points: error handling 3 (7 pts), if/else 3 (4 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
runner_utils._sanitize_git_remote_url (cognitive 16) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:81— runner_utils._sanitize_git_remote_url has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (9 pts), boolean chains 5, error handling 1, ternaries 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
runner_utils._wrap_in_chain_factory (cognitive 16) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:250— runner_utils._wrap_in_chain_factory has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (14 pts), error handling 1 (2 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ModelRetryMiddleware.wrap_model_call (cognitive 16) libs/langchain_v1/langchain/agents/middleware/model_retry.py:221— ModelRetryMiddleware.wrap_model_call has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (11 pts), error handling 2 (4 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ModelRetryMiddleware.awrap_model_call) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
ModelRetryMiddleware.awrap_model_call (cognitive 16) libs/langchain_v1/langchain/agents/middleware/model_retry.py:275— ModelRetryMiddleware.awrap_model_call has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (11 pts), error handling 2 (4 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (ModelRetryMiddleware.wrap_model_call) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
SummarizationMiddleware._find_safe_cutoff_point (cognitive 16) libs/langchain_v1/langchain/agents/middleware/summarization.py:878— SummarizationMiddleware._find_safe_cutoff_point has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 3, loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StateFileSearchMiddleware._handle_glob_search (cognitive 16) libs/partners/anthropic/langchain_anthropic/middleware/file_search.py:203— StateFileSearchMiddleware._handle_glob_search has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (13 pts), boolean chains 1, loops 1, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChatHuggingFace.from_model_id (cognitive 16) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:613— ChatHuggingFace.from_model_id has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (10 pts), loops 2 (4 pts), ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HuggingFaceEndpoint._stream (cognitive 16) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:418— HuggingFaceEndpoint._stream has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (13 pts), loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (HuggingFaceEndpoint._astream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
HuggingFaceEndpoint._astream (cognitive 16) libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:455— HuggingFaceEndpoint._astream has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (13 pts), loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (HuggingFaceEndpoint._stream) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
_utils.parse_url_with_auth (cognitive 16) libs/partners/ollama/langchain_ollama/_utils.py:77— _utils.parse_url_with_auth has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (7 pts), boolean chains 5, error handling 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
Change coupling clique: REDACTED, embeddings.py, llms.py libs/partners/ollama/langchain_ollama/chat_models.py— 3 files — `libs/partners/ollama/langchain_ollama/chat_models.py`, `libs/partners/ollama/langchain_ollama/embeddings.py`, `libs/partners/ollama/langchain_ollama/llms.py` — all change together with no explicit dependency: a fully-connected co-change clique, not 3 separate couplings. They share one concern (thin parallel siblings over a common abstraction), so extract the shared part into ONE unit and the whole clique's coupling clears at once — you do not need to break each pair individually.
D4 · Code Duplication· Near-duplicate member family (17 members, 32 shared lines) · ×1
Near-duplicate member family (17 members, 32 shared lines) libs/core/scripts/check_version.py:28— libs/core/scripts/check_version.py:28-61 | libs/langchain_v1/scripts/check_version.py:28-61 | libs/partners/anthropic/scripts/check_version.py:28-61 | libs/partners/chroma/scripts/check_version.py:28-61 | libs/partners/deepseek/scripts/check_version.py:28-61 | libs/partners/exa/scripts/check_version.py:28-61 | libs/partners/fireworks/scripts/check_version.py:28-61 | libs/partners/groq/scripts/check_version.py:28-61 | libs/partners/huggingface/scripts/check_version.py:28-61 | libs/partners/mistralai/scripts/check_version.py:28-61 | libs/partners/nomic/scripts/check_version.py:28-61 | libs/partners/ollama/scripts/check_version.py:28-61 | libs/partners/openai/scripts/check_version.py:28-61 | libs/partners/openrouter/scripts/check_version.py:28-61 | libs/partners/perplexity/scripts/check_version.py:28-61 | libs/partners/qdrant/scripts/check_version.py:28-61 | libs/partners/xai/scripts/check_version.py:28-61 — These 17 members are variants of one another: a block of 32 lines reported below appears in every one of them, and the pairwise near-duplicate rows they would otherwise produce are collapsed into this row. Read them as one construct written 17 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 17 times.
Near-duplicate member pair (194 shared lines) libs/core/langchain_core/indexing/api.py:310— libs/core/langchain_core/indexing/api.py:310-603 | libs/core/langchain_core/indexing/api.py:649-954 — These two members are variants of one another: 194 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (91 shared lines) libs/core/langchain_core/messages/block_translators/anthropic.py:233— libs/core/langchain_core/messages/block_translators/anthropic.py:233-518 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:153-294 — These two members are variants of one another: 91 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (89 shared lines) libs/core/langchain_core/language_models/llms.py:864— libs/core/langchain_core/language_models/llms.py:864-1072 | libs/core/langchain_core/language_models/llms.py:1145-1351 — These two members are variants of one another: 89 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (70 shared lines) libs/core/langchain_core/tools/base.py:1026— libs/core/langchain_core/tools/base.py:1026-1136 | libs/core/langchain_core/tools/base.py:1154-1267 — These two members are variants of one another: 70 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (62 shared lines) libs/partners/openrouter/langchain_openrouter/chat_models.py:599— libs/partners/openrouter/langchain_openrouter/chat_models.py:599-680 | libs/partners/openrouter/langchain_openrouter/chat_models.py:689-772 — These two members are variants of one another: 62 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (48 shared lines) libs/core/langchain_core/runnables/branch.py:298— libs/core/langchain_core/runnables/branch.py:298-373 | libs/core/langchain_core/runnables/branch.py:382-457 — These two members are variants of one another: 48 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
D4 · Code Duplication· Members sharing a duplicated core (9 members, 50+ identical tokens) · ×1
Members sharing a duplicated core (9 members, 50+ identical tokens) libs/core/langchain_core/language_models/chat_models.py:2435— libs/core/langchain_core/language_models/chat_models.py:2435-2611 | REDACTED:1716-2051 | libs/partners/groq/langchain_groq/chat_models.py:982-1342 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1106-1225 | libs/partners/mistralai/langchain_mistralai/chat_models.py:1023-1345 | libs/partners/ollama/langchain_ollama/chat_models.py:1452-1794 | libs/partners/openai/langchain_openai/chat_models/base.py:2632-2890 | libs/partners/openrouter/langchain_openrouter/chat_models.py:961-1064 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1657-1748 — These 9 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 9 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 9 times.
D4 · Code Duplication· Members sharing a duplicated core (6 members, 50+ identical tokens) · ×1
Members sharing a duplicated core (6 members, 50+ identical tokens) libs/core/langchain_core/messages/content.py:1034— libs/core/langchain_core/messages/content.py:1034-1083 | libs/core/langchain_core/messages/content.py:1096-1149 | libs/core/langchain_core/messages/content.py:1162-1215 | libs/core/langchain_core/messages/content.py:1228-1281 | libs/core/langchain_core/messages/content.py:1295-1344 | libs/core/langchain_core/messages/content.py:1443-1480 — These 6 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 6 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 6 times.
D4 · Code Duplication· Edited copy of a member (108 corresponding lines) · ×1
Edited copy of a member (108 corresponding lines) libs/partners/perplexity/langchain_perplexity/chat_models.py:1207— libs/partners/perplexity/langchain_perplexity/chat_models.py:1207-1315 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1324-1431 — These two members are one piece of code written twice and then edited apart: 108 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (129 corresponding lines) · ×1
Edited copy of a member (129 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1648— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1648-1776 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1813-1943 — These two members are one piece of code written twice and then edited apart: 129 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (86 corresponding lines) · ×1
Edited copy of a member (86 corresponding lines) libs/langchain_v1/langchain/agents/factory.py:287— libs/langchain_v1/langchain/agents/factory.py:287-373 | libs/langchain_v1/langchain/agents/factory.py:379-464 — These two members are one piece of code written twice and then edited apart: 86 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (59 corresponding lines) · ×1
Edited copy of a member (59 corresponding lines) libs/partners/perplexity/langchain_perplexity/chat_models.py:1440— libs/partners/perplexity/langchain_perplexity/chat_models.py:1440-1498 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1507-1567 — These two members are one piece of code written twice and then edited apart: 59 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (63 corresponding lines) · ×1
Edited copy of a member (63 corresponding lines) REDACTED:1392— REDACTED:1392-1454 | REDACTED:1537-1601 — These two members are one piece of code written twice and then edited apart: 63 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (79 corresponding lines) · ×1
Edited copy of a member (79 corresponding lines) libs/partners/chroma/langchain_chroma/vectorstores.py:515— libs/partners/chroma/langchain_chroma/vectorstores.py:515-595 | libs/partners/chroma/langchain_chroma/vectorstores.py:604-682 — These two members are one piece of code written twice and then edited apart: 79 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (85 corresponding lines) · ×1
Edited copy of a member (85 corresponding lines) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:198— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:198-287 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:697-781 — These two members are one piece of code written twice and then edited apart: 85 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (81 corresponding lines) · ×1
Edited copy of a member (81 corresponding lines) libs/core/langchain_core/runnables/base.py:5222— libs/core/langchain_core/runnables/base.py:5222-5302 | libs/core/langchain_core/runnables/base.py:5451-5533 — These two members are one piece of code written twice and then edited apart: 81 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (74 corresponding lines) · ×1
Edited copy of a member (74 corresponding lines) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:260— libs/langchain/langchain_classic/indexes/_sql_record_manager.py:260-333 | libs/langchain/langchain_classic/indexes/_sql_record_manager.py:342-415 — These two members are one piece of code written twice and then edited apart: 74 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (90 corresponding lines) · ×1
Edited copy of a member (90 corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py:297— libs/langchain/langchain_classic/agents/openai_assistant/base.py:297-386 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:430-521 — These two members are one piece of code written twice and then edited apart: 90 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 50+ corresponding lines) · ×1
Edited copies of one member (4 members, 50+ corresponding lines) REDACTED:141— REDACTED:141-199 | libs/partners/groq/langchain_groq/chat_models.py:1533-1595 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:186-235 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1348-1411 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 50 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (55 corresponding lines) · ×1
Edited copy of a member (55 corresponding lines) REDACTED:370— REDACTED:370-469 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:128-182 — These two members are one piece of code written twice and then edited apart: 55 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (139 corresponding lines) · ×1
Edited copy of a member (139 corresponding lines) libs/langchain_v1/langchain/agents/middleware/types.py:1879— libs/langchain_v1/langchain/agents/middleware/types.py:1879-2017 | libs/langchain_v1/langchain/agents/middleware/types.py:2052-2203 — These two members are one piece of code written twice and then edited apart: 139 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (66 corresponding lines) · ×1
Edited copy of a member (66 corresponding lines) libs/langchain/langchain_classic/chains/question_answering/chain.py:118— libs/langchain/langchain_classic/chains/question_answering/chain.py:118-183 | libs/langchain/langchain_classic/chains/summarize/chain.py:84-169 — These two members are one piece of code written twice and then edited apart: 66 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (158 corresponding lines) · ×1
Edited copy of a member (158 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1418— libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1418-1575 | libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:1592-1764 — These two members are one piece of code written twice and then edited apart: 158 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (57 corresponding lines) · ×1
Edited copy of a member (57 corresponding lines) libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:773— libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:773-831 | libs/langchain/langchain_classic/smith/evaluation/runner_utils.py:937-993 — These two members are one piece of code written twice and then edited apart: 57 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (45 corresponding lines) · ×1
Edited copy of a member (45 corresponding lines) libs/partners/fireworks/langchain_fireworks/llms.py:137— libs/partners/fireworks/langchain_fireworks/llms.py:137-181 | libs/partners/fireworks/langchain_fireworks/llms.py:190-239 — These two members are one piece of code written twice and then edited apart: 45 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 27+ corresponding lines) · ×1
Edited copies of one member (3 members, 27+ corresponding lines) libs/partners/qdrant/langchain_qdrant/qdrant.py:1045— libs/partners/qdrant/langchain_qdrant/qdrant.py:1045-1071 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2204-2236 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:2245-2277 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 27 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 41+ corresponding lines) · ×1
Edited copies of one member (3 members, 41+ corresponding lines) REDACTED:1664— REDACTED:1664-1704 | libs/partners/groq/langchain_groq/chat_models.py:929-969 | libs/partners/openrouter/langchain_openrouter/chat_models.py:907-950 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 41 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 29+ corresponding lines) · ×1
Edited copies of one member (4 members, 29+ corresponding lines) libs/core/langchain_core/retrievers.py:182— libs/core/langchain_core/retrievers.py:182-234 | libs/core/langchain_core/retrievers.py:243-295 | libs/langchain/langchain_classic/retrievers/ensemble.py:111-139 | libs/langchain/langchain_classic/retrievers/ensemble.py:148-180 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 29 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (52 corresponding lines) · ×1
Edited copy of a member (52 corresponding lines) libs/langchain/langchain_classic/embeddings/base.py:31— libs/langchain/langchain_classic/embeddings/base.py:31-82 | libs/langchain_v1/langchain/embeddings/base.py:104-155 — These two members are one piece of code written twice and then edited apart: 52 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 32+ corresponding lines) · ×1
Edited copies of one member (4 members, 32+ corresponding lines) libs/core/langchain_core/prompts/base.py:388— libs/core/langchain_core/prompts/base.py:388-429 | libs/langchain/langchain_classic/agents/agent.py:183-214 | libs/langchain/langchain_classic/agents/agent.py:319-354 | libs/langchain/langchain_classic/chains/base.py:760-797 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 32 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (294 corresponding lines) · ×1
Edited copy of a member (294 corresponding lines) libs/langchain/langchain_classic/chat_models/base.py:89— libs/langchain/langchain_classic/chat_models/base.py:89-386 | libs/langchain_v1/langchain/chat_models/base.py:240-533 — These two members are one piece of code written twice and then edited apart: 294 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 37+ corresponding lines) · ×1
Edited copies of one member (5 members, 37+ corresponding lines) libs/core/langchain_core/callbacks/manager.py:1479— libs/core/langchain_core/callbacks/manager.py:1479-1515 | libs/core/langchain_core/callbacks/manager.py:1527-1575 | libs/core/langchain_core/callbacks/manager.py:1586-1623 | libs/core/langchain_core/callbacks/manager.py:2067-2104 | libs/core/langchain_core/callbacks/manager.py:2159-2196 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 37 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 26+ corresponding lines) · ×1
Edited copies of one member (3 members, 26+ corresponding lines) libs/langchain/langchain_classic/output_parsers/fix.py:71— libs/langchain/langchain_classic/output_parsers/fix.py:71-105 | libs/langchain/langchain_classic/output_parsers/fix.py:109-143 | libs/langchain/langchain_classic/output_parsers/retry.py:235-260 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 26 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 37+ corresponding lines) · ×1
Edited copies of one member (3 members, 37+ corresponding lines) libs/core/langchain_core/callbacks/manager.py:1374— libs/core/langchain_core/callbacks/manager.py:1374-1416 | libs/core/langchain_core/callbacks/manager.py:1425-1470 | libs/core/langchain_core/callbacks/manager.py:2020-2056 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 37 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 23+ corresponding lines) · ×1
Edited copies of one member (5 members, 23+ corresponding lines) libs/core/langchain_core/utils/utils.py:220— libs/core/langchain_core/utils/utils.py:220-258 | libs/core/langchain_core/utils/utils.py:267-310 | libs/partners/groq/langchain_groq/chat_models.py:510-535 | libs/partners/openrouter/langchain_openrouter/chat_models.py:381-406 | libs/partners/perplexity/langchain_perplexity/chat_models.py:877-899 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 23 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 24+ corresponding lines) · ×1
Edited copies of one member (4 members, 24+ corresponding lines) libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:102— libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:102-134 | libs/langchain/langchain_classic/agents/openai_functions_agent/base.py:142-167 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:209-232 | libs/langchain/langchain_classic/agents/openai_functions_multi_agent/base.py:240-263 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 24 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (142 corresponding lines) · ×1
Edited copy of a member (142 corresponding lines) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1229— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1229-1370 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1466-1611 — These two members are one piece of code written twice and then edited apart: 142 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 17+ corresponding lines) · ×1
Edited copies of one member (3 members, 17+ corresponding lines) libs/core/langchain_core/tracers/core.py:259— libs/core/langchain_core/tracers/core.py:259-275 | libs/core/langchain_core/tracers/core.py:410-426 | libs/core/langchain_core/tracers/langchain.py:275-307 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 17 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 24+ corresponding lines) · ×1
Edited copies of one member (5 members, 24+ corresponding lines) libs/langchain/langchain_classic/agents/chat/base.py:136— libs/langchain/langchain_classic/agents/chat/base.py:136-174 | libs/langchain/langchain_classic/agents/conversational/base.py:135-178 | libs/langchain/langchain_classic/agents/conversational_chat/base.py:146-181 | libs/langchain/langchain_classic/agents/mrkl/base.py:126-159 | libs/langchain/langchain_classic/agents/structured_chat/base.py:136-159 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 24 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 11+ corresponding lines) · ×1
Edited copies of one member (5 members, 11+ corresponding lines) libs/partners/groq/langchain_groq/chat_models.py:628— libs/partners/groq/langchain_groq/chat_models.py:628-640 | libs/partners/mistralai/langchain_mistralai/chat_models.py:704-716 | libs/partners/ollama/langchain_ollama/chat_models.py:1192-1202 | libs/partners/openai/langchain_openai/chat_models/base.py:2359-2373 | libs/partners/openrouter/langchain_openrouter/chat_models.py:542-554 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 11 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 91+ corresponding lines) · ×1
Edited copies of one member (3 members, 91+ corresponding lines) libs/langchain/langchain_classic/agents/openai_tools/base.py:23— libs/langchain/langchain_classic/agents/openai_tools/base.py:23-113 | libs/langchain/langchain_classic/agents/tool_calling_agent/base.py:25-117 | libs/langchain/langchain_classic/agents/xml/base.py:123-236 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 91 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 33+ corresponding lines) · ×1
Edited copies of one member (3 members, 33+ corresponding lines) libs/core/langchain_core/messages/content.py:987— libs/core/langchain_core/messages/content.py:987-1021 | libs/core/langchain_core/messages/content.py:1355-1389 | libs/core/langchain_core/messages/content.py:1398-1430 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 33 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 9+ corresponding lines) · ×1
Edited copies of one member (3 members, 9+ corresponding lines) libs/langchain/langchain_classic/agents/react/base.py:59— libs/langchain/langchain_classic/agents/react/base.py:59-67 | libs/langchain/langchain_classic/agents/react/base.py:154-162 | libs/langchain/langchain_classic/agents/self_ask_with_search/base.py:55-63 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 9 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 19+ corresponding lines) · ×1
Edited copies of one member (3 members, 19+ corresponding lines) libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:242— libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:242-261 | libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:265-283 | libs/langchain/langchain_classic/evaluation/embedding_distance/base.py:287-305 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 19 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 27+ corresponding lines) · ×1
Edited copies of one member (4 members, 27+ corresponding lines) libs/langchain/langchain_classic/indexes/vectorstore.py:41— libs/langchain/langchain_classic/indexes/vectorstore.py:41-67 | libs/langchain/langchain_classic/indexes/vectorstore.py:76-102 | libs/langchain/langchain_classic/indexes/vectorstore.py:111-137 | libs/langchain/langchain_classic/indexes/vectorstore.py:146-172 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 27 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 21+ corresponding lines) · ×1
Edited copies of one member (4 members, 21+ corresponding lines) libs/langchain/langchain_classic/agents/openai_assistant/base.py:546— libs/langchain/langchain_classic/agents/openai_assistant/base.py:546-567 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:570-590 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:703-724 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:727-747 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 21 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 25+ corresponding lines) · ×1
Edited copies of one member (3 members, 25+ corresponding lines) libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:182— libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:182-208 | libs/langchain/langchain_classic/chains/question_answering/chain.py:248-279 | libs/langchain/langchain_classic/chains/summarize/chain.py:202-226 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 25 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 10+ corresponding lines) · ×1
Edited copies of one member (4 members, 10+ corresponding lines) libs/partners/openai/langchain_openai/decisions/base.py:294— libs/partners/openai/langchain_openai/decisions/base.py:294-303 | libs/partners/openai/langchain_openai/decisions/base.py:306-315 | libs/partners/openai/langchain_openai/decisions/classifier.py:268-277 | libs/partners/openai/langchain_openai/decisions/classifier.py:283-292 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 10 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 11+ corresponding lines) · ×1
Edited copies of one member (3 members, 11+ corresponding lines) libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:450— libs/langchain/langchain_classic/chains/conversational_retrieval/base.py:450-495 | libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:153-164 | libs/langchain/langchain_classic/chains/summarize/chain.py:183-193 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 11 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 12+ corresponding lines) · ×1
Edited copies of one member (3 members, 12+ corresponding lines) libs/core/langchain_core/output_parsers/json.py:109— libs/core/langchain_core/output_parsers/json.py:109-127 | libs/core/langchain_core/output_parsers/pydantic.py:97-114 | libs/langchain/langchain_classic/output_parsers/yaml.py:49-60 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 12 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 4+ corresponding lines) · ×1
Edited copies of one member (3 members, 4+ corresponding lines) libs/partners/openai/langchain_openai/chat_models/azure.py:882— libs/partners/openai/langchain_openai/chat_models/azure.py:882-885 | libs/partners/openai/langchain_openai/chat_models/base.py:3866-3869 | libs/partners/xai/langchain_xai/chat_models.py:624-627 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 4 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (5 corresponding lines) · ×1
Edited copy of a member (5 corresponding lines) libs/core/langchain_core/indexing/api.py:45— libs/core/langchain_core/indexing/api.py:45-49 | libs/langchain/langchain_classic/embeddings/cache.py:29-40 — These two members are one piece of code written twice and then edited apart: 5 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (4 corresponding lines) · ×1
Edited copy of a member (4 corresponding lines) libs/core/langchain_core/language_models/chat_models.py:1930— libs/core/langchain_core/language_models/chat_models.py:1930-1933 | libs/core/langchain_core/language_models/llms.py:811-814 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (2 corresponding lines) · ×1
Edited copy of a member (2 corresponding lines) libs/core/langchain_core/language_models/chat_models.py:1919— libs/core/langchain_core/language_models/chat_models.py:1919-1920 | libs/core/langchain_core/language_models/llms.py:800-801 — These two members are one piece of code written twice and then edited apart: 2 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (266–278 lines × 2) REDACTED:1716— REDACTED:1716-1993 | libs/partners/ollama/langchain_ollama/chat_models.py:1452-1717 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1716` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: `ChatFireworks` names `langchain_fireworks` in one and `langchain_fireworks.chat_models` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (62–256 lines × 2) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1106— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1106-1167 | libs/partners/mistralai/langchain_mistralai/chat_models.py:1023-1278 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/mistralai/langchain_mistralai/chat_models.py:1023` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1168` calls `convert_to_openai_tool` and `libs/partners/mistralai/langchain_mistralai/chat_models.py:1281` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (145–180 lines × 4) libs/langchain_v1/langchain/agents/middleware/types.py:965— libs/langchain_v1/langchain/agents/middleware/types.py:965-1121 | libs/langchain_v1/langchain/agents/middleware/types.py:1154-1298 | libs/langchain_v1/langchain/agents/middleware/types.py:1331-1510 | libs/langchain_v1/langchain/agents/middleware/types.py:1543-1688 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (114–132 lines × 2) libs/langchain/langchain_classic/agents/react/agent.py:25— libs/langchain/langchain_classic/agents/react/agent.py:25-138 | libs/langchain/langchain_classic/agents/structured_chat/base.py:174-305 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/react/agent.py:25` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (127–128 lines × 2) libs/core/langchain_core/indexing/api.py:310— libs/core/langchain_core/indexing/api.py:310-436 | libs/core/langchain_core/indexing/api.py:649-776 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (72–89 lines × 2) libs/langchain/langchain_classic/agents/agent_toolkits/vectorstore/base.py:40— libs/langchain/langchain_classic/agents/agent_toolkits/vectorstore/base.py:40-111 | libs/langchain/langchain_classic/agents/agent_toolkits/vectorstore/base.py:132-220 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (83–85 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1649— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1649-1731 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1814-1898 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (62–74 lines × 2) libs/core/langchain_core/language_models/_compat_bridge.py:616— libs/core/langchain_core/language_models/_compat_bridge.py:616-689 | libs/core/langchain_core/language_models/_compat_bridge.py:707-768 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (68–70 lines × 2) libs/partners/perplexity/langchain_perplexity/chat_models.py:1244— libs/partners/perplexity/langchain_perplexity/chat_models.py:1244-1313 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1362-1429 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (56–58 lines × 2) libs/core/langchain_core/callbacks/manager.py:1762— libs/core/langchain_core/callbacks/manager.py:1762-1817 | libs/core/langchain_core/callbacks/manager.py:2290-2347 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on. Note first that the copies are not typed on the same thing: the declarations holding them bind `self` to `CallbackManagerForChainGroup` in one and `AsyncCallbackManagerForChainGroup` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (58 lines × 2) libs/partners/ollama/langchain_ollama/chat_models.py:1236— libs/partners/ollama/langchain_ollama/chat_models.py:1236-1293 | libs/partners/ollama/langchain_ollama/chat_models.py:1318-1375 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (52–54 lines × 2) libs/core/langchain_core/messages/ai.py:735— libs/core/langchain_core/messages/ai.py:735-786 | libs/core/langchain_core/messages/ai.py:796-849 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/ai.py:735` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (53–54 lines × 2) libs/langchain/langchain_classic/agents/openai_assistant/base.py:616— libs/langchain/langchain_classic/agents/openai_assistant/base.py:616-669 | libs/langchain/langchain_classic/agents/openai_assistant/base.py:770-822 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/openai_assistant/base.py:616` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (45 lines × 2) libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:217— libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:217-261 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:721-765 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:217` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (42–43 lines × 2) libs/core/langchain_core/messages/block_translators/openai.py:919— libs/core/langchain_core/messages/block_translators/openai.py:919-960 | libs/core/langchain_core/messages/block_translators/openai.py:970-1012 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (43 lines × 2) libs/partners/qdrant/langchain_qdrant/vectorstores.py:1734— libs/partners/qdrant/langchain_qdrant/vectorstores.py:1734-1776 | libs/partners/qdrant/langchain_qdrant/vectorstores.py:1901-1943 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (42 lines × 2) libs/core/langchain_core/runnables/base.py:3578— libs/core/langchain_core/runnables/base.py:3578-3619 | libs/core/langchain_core/runnables/base.py:3709-3750 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3578` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (41–42 lines × 2) libs/partners/openrouter/langchain_openrouter/chat_models.py:633— libs/partners/openrouter/langchain_openrouter/chat_models.py:633-674 | libs/partners/openrouter/langchain_openrouter/chat_models.py:726-766 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openrouter/langchain_openrouter/chat_models.py:633` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (39–42 lines × 2) libs/partners/perplexity/langchain_perplexity/chat_models.py:1460— libs/partners/perplexity/langchain_perplexity/chat_models.py:1460-1498 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1526-1567 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/perplexity/langchain_perplexity/chat_models.py:1526` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (41 lines × 2) libs/core/langchain_core/language_models/llms.py:967— libs/core/langchain_core/language_models/llms.py:967-1007 | libs/core/langchain_core/language_models/llms.py:1237-1277 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/llms.py:967` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (37 lines × 2) libs/langchain/langchain_classic/chat_models/base.py:552— libs/langchain/langchain_classic/chat_models/base.py:552-588 | libs/langchain_v1/langchain/chat_models/base.py:548-584 — before extracting anything, compare `libs/langchain/langchain_classic/chat_models/base.py` and `libs/langchain_v1/langchain/chat_models/base.py` as WHOLE FILES: this scan already matched 13 separate duplicated blocks between them, totalling at least 255 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (30–36 lines × 2) libs/core/langchain_core/_security/_transport.py:78— libs/core/langchain_core/_security/_transport.py:78-113 | libs/core/langchain_core/_security/_transport.py:160-189 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/_security/_transport.py:78` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (36 lines × 2) libs/core/langchain_core/runnables/retry.py:260— libs/core/langchain_core/runnables/retry.py:260-295 | libs/core/langchain_core/runnables/retry.py:335-370 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/retry.py:260` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17–35 lines × 2) libs/langchain/langchain_classic/agents/conversational/base.py:135— libs/langchain/langchain_classic/agents/conversational/base.py:135-169 | libs/langchain/langchain_classic/agents/structured_chat/base.py:136-152 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain/langchain_classic/agents/conversational/base.py:135` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. Note first that the copies are not typed on the same thing: `LLMChain` names `langchain_classic.chains` in one and `langchain_classic.chains.llm` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (35 lines × 2) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:296— libs/langchain/langchain_classic/indexes/_sql_record_manager.py:296-330 | libs/langchain/langchain_classic/indexes/_sql_record_manager.py:378-412 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (23–35 lines × 2) libs/partners/chroma/langchain_chroma/vectorstores.py:115— libs/partners/chroma/langchain_chroma/vectorstores.py:115-149 | libs/partners/qdrant/langchain_qdrant/_utils.py:14-36 — before extracting anything, compare `libs/partners/chroma/langchain_chroma/vectorstores.py` and `libs/partners/qdrant/langchain_qdrant/_utils.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 61 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (31–33 lines × 2) libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:848— libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:848-880 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:915-945 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:848` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (28–32 lines × 2) libs/core/langchain_core/runnables/base.py:374— libs/core/langchain_core/runnables/base.py:374-405 | libs/core/langchain_core/runnables/base.py:409-436 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20–32 lines × 2) libs/langchain_v1/langchain/agents/middleware/file_search.py:269— libs/langchain_v1/langchain/agents/middleware/file_search.py:269-288 | libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py:844-875 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (17–32 lines × 2) libs/partners/openai/langchain_openai/llms/base.py:453— libs/partners/openai/langchain_openai/llms/base.py:453-484 | libs/partners/openai/langchain_openai/llms/base.py:537-553 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (27–30 lines × 2) libs/core/langchain_core/language_models/chat_models.py:1046— libs/core/langchain_core/language_models/chat_models.py:1046-1075 | libs/core/langchain_core/language_models/chat_models.py:1187-1213 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (28–29 lines × 2) libs/core/langchain_core/messages/ai.py:244— libs/core/langchain_core/messages/ai.py:244-272 | libs/core/langchain_core/messages/ai.py:447-474 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (25–28 lines × 2) libs/core/langchain_core/messages/block_translators/bedrock_converse.py:36— libs/core/langchain_core/messages/block_translators/bedrock_converse.py:36-60 | libs/core/langchain_core/messages/block_translators/google_genai.py:125-152 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/messages/block_translators/google_genai.py:153` calls `get` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py:62` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (27–28 lines × 2) libs/core/langchain_core/output_parsers/list.py:75— libs/core/langchain_core/output_parsers/list.py:75-102 | libs/core/langchain_core/output_parsers/list.py:110-136 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26–28 lines × 2) libs/partners/openai/langchain_openai/chat_models/base.py:4549— libs/partners/openai/langchain_openai/chat_models/base.py:4549-4576 | libs/partners/openai/langchain_openai/chat_models/base.py:4597-4622 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (26 lines × 16) libs/core/scripts/check_version.py:33— libs/core/scripts/check_version.py:33-58 | libs/partners/anthropic/scripts/check_version.py:33-58 | libs/partners/chroma/scripts/check_version.py:33-58 | libs/partners/deepseek/scripts/check_version.py:33-58 | libs/partners/exa/scripts/check_version.py:33-58 | libs/partners/fireworks/scripts/check_version.py:33-58 | libs/partners/groq/scripts/check_version.py:33-58 | libs/partners/huggingface/scripts/check_version.py:33-58 | libs/partners/mistralai/scripts/check_version.py:33-58 | libs/partners/nomic/scripts/check_version.py:33-58 | libs/partners/ollama/scripts/check_version.py:33-58 | libs/partners/openai/scripts/check_version.py:33-58 | libs/partners/openrouter/scripts/check_version.py:33-58 | libs/partners/perplexity/scripts/check_version.py:33-58 | libs/partners/qdrant/scripts/check_version.py:33-58 | libs/partners/xai/scripts/check_version.py:33-58 — before extracting anything, compare `libs/core/scripts/check_version.py` and `libs/partners/anthropic/scripts/check_version.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 58 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (25–26 lines × 2) libs/core/langchain_core/runnables/fallbacks.py:318— libs/core/langchain_core/runnables/fallbacks.py:318-342 | libs/core/langchain_core/runnables/fallbacks.py:416-441 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/fallbacks.py:318` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24–25 lines × 2) libs/core/langchain_core/runnables/base.py:2591— libs/core/langchain_core/runnables/base.py:2591-2614 | libs/core/langchain_core/runnables/base.py:2675-2699 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:2591` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (21–23 lines × 4) libs/langchain_v1/langchain/agents/middleware/model_retry.py:244— libs/langchain_v1/langchain/agents/middleware/model_retry.py:244-264 | libs/langchain_v1/langchain/agents/middleware/model_retry.py:298-318 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:326-348 | libs/langchain_v1/langchain/agents/middleware/tool_retry.py:390-412 — before extracting anything, compare `libs/langchain_v1/langchain/agents/middleware/model_retry.py` and `libs/langchain_v1/langchain/agents/middleware/tool_retry.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 81 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (20–23 lines × 2) libs/partners/groq/langchain_groq/chat_models.py:1533— libs/partners/groq/langchain_groq/chat_models.py:1533-1552 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1348-1370 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/partners/groq/langchain_groq/chat_models.py:1553` calls `get`, `dict` and `libs/partners/openrouter/langchain_openrouter/chat_models.py:1371` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (16–22 lines × 6) libs/core/langchain_core/messages/content.py:1068— libs/core/langchain_core/messages/content.py:1068-1083 | libs/core/langchain_core/messages/content.py:1134-1149 | libs/core/langchain_core/messages/content.py:1200-1215 | libs/core/langchain_core/messages/content.py:1266-1281 | libs/core/langchain_core/messages/content.py:1323-1344 | libs/core/langchain_core/messages/content.py:1465-1480 — all 6 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/content.py:1323` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (20–21 lines × 2) libs/core/langchain_core/runnables/fallbacks.py:221— libs/core/langchain_core/runnables/fallbacks.py:221-241 | libs/core/langchain_core/runnables/fallbacks.py:535-554 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17–20 lines × 2) libs/core/langchain_core/runnables/base.py:2464— libs/core/langchain_core/runnables/base.py:2464-2480 | libs/core/langchain_core/runnables/base.py:3631-3650 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3631` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (18–19 lines × 3) REDACTED:1686— REDACTED:1686-1704 | libs/partners/groq/langchain_groq/chat_models.py:951-969 | libs/partners/openrouter/langchain_openrouter/chat_models.py:933-950 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (16–18 lines × 3) libs/core/langchain_core/messages/block_translators/langchain_v0.py:92— libs/core/langchain_core/messages/block_translators/langchain_v0.py:92-107 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:160-177 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:230-247 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/langchain_v0.py:160` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16–18 lines × 2) libs/core/langchain_core/language_models/chat_models.py:854— libs/core/langchain_core/language_models/chat_models.py:854-871 | libs/core/langchain_core/language_models/chat_models.py:992-1007 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15–18 lines × 2) libs/core/langchain_core/messages/block_translators/langchain_v0.py:136— libs/core/langchain_core/messages/block_translators/langchain_v0.py:136-150 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:204-221 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/langchain_v0.py:204` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 4) libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:180— libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py:180-196 | libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py:152-168 | libs/langchain/langchain_classic/chains/combine_documents/refine.py:127-143 | libs/langchain/langchain_classic/chains/combine_documents/stuff.py:175-191 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 4 call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (16–17 lines × 3) libs/core/langchain_core/utils/utils.py:291— libs/core/langchain_core/utils/utils.py:291-307 | libs/partners/groq/langchain_groq/chat_models.py:517-532 | libs/partners/openrouter/langchain_openrouter/chat_models.py:388-403 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (15–16 lines × 4) libs/core/langchain_core/utils/utils.py:234— libs/core/langchain_core/utils/utils.py:234-248 | libs/core/langchain_core/utils/utils.py:287-302 | libs/partners/groq/langchain_groq/chat_models.py:513-527 | libs/partners/openrouter/langchain_openrouter/chat_models.py:384-398 — there are 4 copies across 3 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/core/langchain_core/utils/utils.py:233` calls `get` and `libs/core/langchain_core/utils/utils.py:284` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (12–14 lines × 5) REDACTED:2038— REDACTED:2038-2049 | libs/partners/groq/langchain_groq/chat_models.py:1327-1340 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1212-1223 | libs/partners/ollama/langchain_ollama/chat_models.py:1781-1792 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1051-1062 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2038` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 4) libs/core/langchain_core/language_models/chat_models.py:840— libs/core/langchain_core/language_models/chat_models.py:840-853 | libs/core/langchain_core/language_models/chat_models.py:977-990 | libs/core/langchain_core/language_models/chat_models.py:2025-2038 | libs/core/langchain_core/language_models/chat_models.py:2180-2193 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (13–14 lines × 4) libs/core/langchain_core/runnables/fallbacks.py:179— libs/core/langchain_core/runnables/fallbacks.py:179-191 | libs/core/langchain_core/runnables/fallbacks.py:232-245 | libs/core/langchain_core/runnables/fallbacks.py:482-494 | libs/core/langchain_core/runnables/fallbacks.py:546-558 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/fallbacks.py:179` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13–14 lines × 2) libs/core/langchain_core/runnables/base.py:3621— libs/core/langchain_core/runnables/base.py:3621-3634 | libs/core/langchain_core/runnables/base.py:3752-3764 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/runnables/base.py:3621` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–14 lines × 2) libs/core/langchain_core/tracers/core.py:233— libs/core/langchain_core/tracers/core.py:233-246 | libs/core/langchain_core/tracers/langchain.py:294-304 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/tracers/core.py:233` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12–13 lines × 6) libs/core/langchain_core/messages/block_translators/langchain_v0.py:92— libs/core/langchain_core/messages/block_translators/langchain_v0.py:92-103 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:117-129 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:161-173 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:187-199 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:231-243 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:257-269 — all 6 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/langchain_v0.py:117` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12–13 lines × 3) libs/core/langchain_core/messages/block_translators/anthropic.py:347— libs/core/langchain_core/messages/block_translators/anthropic.py:347-359 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:221-232 | libs/core/langchain_core/messages/block_translators/bedrock_converse.py:268-280 — before extracting anything, compare `libs/core/langchain_core/messages/block_translators/anthropic.py` and `libs/core/langchain_core/messages/block_translators/bedrock_converse.py` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/core/langchain_core/messages/block_translators/bedrock_converse.py:284` calls `pop` and `libs/core/langchain_core/messages/block_translators/anthropic.py:360` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11–12 lines × 7) libs/core/langchain_core/messages/block_translators/langchain_v0.py:92— libs/core/langchain_core/messages/block_translators/langchain_v0.py:92-102 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:117-128 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:161-172 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:187-198 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:231-242 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:257-268 | libs/core/langchain_core/messages/block_translators/langchain_v0.py:289-300 — all 7 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/messages/block_translators/langchain_v0.py:117` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9–12 lines × 3) libs/partners/openai/langchain_openai/chat_models/_compat.py:330— libs/partners/openai/langchain_openai/chat_models/_compat.py:330-341 | libs/partners/openai/langchain_openai/chat_models/_compat.py:351-359 | libs/partners/openai/langchain_openai/chat_models/_compat.py:376-384 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (10–12 lines × 2) libs/partners/openai/langchain_openai/embeddings/base.py:624— libs/partners/openai/langchain_openai/embeddings/base.py:624-633 | libs/partners/openai/langchain_openai/embeddings/base.py:698-709 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/partners/openai/langchain_openai/embeddings/base.py:698` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–11 lines × 9) libs/core/langchain_core/language_models/chat_models.py:2601— libs/core/langchain_core/language_models/chat_models.py:2601-2610 | REDACTED:2042-2050 | libs/partners/groq/langchain_groq/chat_models.py:1333-1341 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1216-1224 | libs/partners/mistralai/langchain_mistralai/chat_models.py:1335-1344 | libs/partners/ollama/langchain_ollama/chat_models.py:1785-1793 | libs/partners/openai/langchain_openai/chat_models/base.py:2879-2889 | libs/partners/openrouter/langchain_openrouter/chat_models.py:1055-1063 | libs/partners/perplexity/langchain_perplexity/chat_models.py:1736-1746 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_models.py:2601` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–10 lines × 4) libs/core/langchain_core/utils/utils.py:233— libs/core/langchain_core/utils/utils.py:233-241 | libs/partners/groq/langchain_groq/chat_models.py:512-520 | libs/partners/openai/langchain_openai/embeddings/base.py:352-361 | libs/partners/openrouter/langchain_openrouter/chat_models.py:383-391 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 4 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 4 times. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/utils/utils.py:233` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (10 lines × 4) libs/langchain/langchain_classic/chains/loading.py:98— libs/langchain/langchain_classic/chains/loading.py:98-107 | libs/langchain/langchain_classic/chains/loading.py:366-375 | libs/langchain/langchain_classic/chains/loading.py:603-612 | libs/langchain/langchain_classic/chains/loading.py:635-644 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/langchain/langchain_classic/chains/loading.py:376` calls `load_chain_from_config`, `load_chain`, `pop` and `libs/langchain/langchain_classic/chains/loading.py:108` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (9–10 lines × 2) libs/langchain/langchain_classic/chains/llm_math/base.py:234— libs/langchain/langchain_classic/chains/llm_math/base.py:234-243 | libs/langchain/langchain_classic/chains/llm_math/base.py:258-266 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8–9 lines × 4) libs/core/langchain_core/language_models/chat_models.py:530— libs/core/langchain_core/language_models/chat_models.py:530-537 | libs/core/langchain_core/language_models/chat_models.py:553-561 | libs/core/langchain_core/language_models/llms.py:385-393 | libs/core/langchain_core/language_models/llms.py:409-417 — there are 4 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/language_models/chat_models.py:553` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9 lines × 3) libs/langchain/langchain_classic/agents/agent.py:206— libs/langchain/langchain_classic/agents/agent.py:206-214 | libs/langchain/langchain_classic/agents/agent.py:346-354 | libs/langchain/langchain_classic/chains/base.py:789-797 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `libs/langchain/langchain_classic/agents/agent.py:344` calls `mkdir` and `libs/langchain/langchain_classic/agents/agent.py:204` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8 lines × 4) REDACTED:1329— REDACTED:1329-1336 | libs/partners/groq/langchain_groq/chat_models.py:628-635 | libs/partners/openai/langchain_openai/chat_models/base.py:2359-2366 | libs/partners/openrouter/langchain_openrouter/chat_models.py:542-549 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place.
Duplicated block (8 lines × 3) libs/core/langchain_core/callbacks/base.py:1041— libs/core/langchain_core/callbacks/base.py:1041-1048 | libs/core/langchain_core/callbacks/manager.py:1748-1755 | libs/core/langchain_core/callbacks/manager.py:2276-2283 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `libs/core/langchain_core/callbacks/base.py:1041` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 16) libs/core/langchain_core/callbacks/__init__.py:125— libs/core/langchain_core/callbacks/__init__.py:125-132 | libs/core/langchain_core/decisions/__init__.py:70-77 | libs/core/langchain_core/document_loaders/__init__.py:32-39 | libs/core/langchain_core/documents/__init__.py:48-55 | libs/core/langchain_core/embeddings/__init__.py:24-31 | libs/core/langchain_core/example_selectors/__init__.py:40-47 | libs/core/langchain_core/indexing/__init__.py:46-53 | libs/core/langchain_core/language_models/__init__.py:109-116 | libs/core/langchain_core/load/__init__.py:37-44 | libs/core/langchain_core/messages/__init__.py:205-212 | libs/core/langchain_core/outputs/__init__.py:59-66 | libs/core/langchain_core/prompts/__init__.py:94-101 | libs/core/langchain_core/runnables/__init__.py:129-136 | libs/core/langchain_core/tools/__init__.py:88-95 | libs/core/langchain_core/tracers/__init__.py:43-50 | libs/core/langchain_core/utils/__init__.py:104-111 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 16 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 16 times.
Duplicated block (16 lines × 5) libs/langchain/langchain_classic/agents/agent_toolkits/csv/__init__.py:5— libs/langchain/langchain_classic/agents/agent_toolkits/csv/__init__.py:5-20 | libs/langchain/langchain_classic/agents/agent_toolkits/pandas/__init__.py:5-20 | libs/langchain/langchain_classic/agents/agent_toolkits/python/__init__.py:5-20 | libs/langchain/langchain_classic/agents/agent_toolkits/spark/__init__.py:5-20 | libs/langchain/langchain_classic/agents/agent_toolkits/xorbits/__init__.py:5-20 — `libs/langchain/langchain_classic/agents/agent_toolkits/csv/__init__.py` and `libs/langchain/langchain_classic/agents/agent_toolkits/pandas/__init__.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 1 separate duplicated blocks between them, totalling at least 16 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (5 lines × 4) REDACTED:1491— REDACTED:1491-1495 | libs/partners/groq/langchain_groq/chat_models.py:880-884 | libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py:1230-1234 | libs/partners/openrouter/langchain_openrouter/chat_models.py:821-825 — before extracting anything, compare `REDACTED` and `libs/partners/groq/langchain_groq/chat_models.py` as WHOLE FILES: this scan already matched 8 separate duplicated blocks between them, totalling at least 104 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
D4 · Code Duplication· Edited copies of one member (3 members, 22+ corresponding lines) · ×1
Edited copies of one member (3 members, 22+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1718— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1718-1739 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1770-1810 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1815-1855 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 22 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (77 corresponding lines) · ×1
Edited copy of a member (77 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1646— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1646-1724 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1727-1803 — These two members are one piece of code written twice and then edited apart: 77 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 17+ corresponding lines) · ×1
Edited copies of one member (4 members, 17+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1302— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1302-1319 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1535-1553 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1558-1576 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1620-1636 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 17 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 14+ corresponding lines) · ×1
Edited copies of one member (5 members, 14+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1172— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1172-1187 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1192-1207 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1212-1232 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1237-1250 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1255-1272 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 14 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (84 corresponding lines) · ×1
Edited copy of a member (84 corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2960— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2960-3075 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:3078-3161 — These two members are one piece of code written twice and then edited apart: 84 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 15+ corresponding lines) · ×1
Edited copies of one member (5 members, 15+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:308— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:308-322 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1054-1070 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1075-1093 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1131-1148 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1153-1167 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 15 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 25+ corresponding lines) · ×1
Edited copies of one member (4 members, 25+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1003— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1003-1042 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1045-1069 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1072-1099 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:1102-1129 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 25 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 14+ corresponding lines) · ×1
Edited copies of one member (3 members, 14+ corresponding lines) libs/standard-tests/langchain_tests/unit_tests/chat_models.py:946— libs/standard-tests/langchain_tests/unit_tests/chat_models.py:946-969 | libs/standard-tests/langchain_tests/unit_tests/embeddings.py:117-137 | libs/standard-tests/langchain_tests/unit_tests/tools.py:86-99 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 14 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 20+ corresponding lines) · ×1
Edited copies of one member (4 members, 20+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:206— libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:206-225 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:228-247 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:557-576 | libs/standard-tests/langchain_tests/integration_tests/vectorstores.py:581-600 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 20 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 6+ corresponding lines) · ×1
Edited copies of one member (3 members, 6+ corresponding lines) libs/standard-tests/langchain_tests/integration_tests/base_store.py:94— libs/standard-tests/langchain_tests/integration_tests/base_store.py:94-99 | libs/standard-tests/langchain_tests/integration_tests/base_store.py:136-146 | libs/standard-tests/langchain_tests/integration_tests/base_store.py:240-245 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 6 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Duplicated block (10–12 lines × 3) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:755— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:755-766 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:773-782 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:789-798 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (10–11 lines × 4) libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2336— libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2336-2345 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2356-2365 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2418-2427 | libs/standard-tests/langchain_tests/integration_tests/chat_models.py:2438-2448 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (9–10 lines × 3) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1541— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1541-1549 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1565-1574 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1626-1634 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1565` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7–9 lines × 2) libs/langchain_v1/examples/mcp/multi_server.py:37— libs/langchain_v1/examples/mcp/multi_server.py:37-43 | libs/langchain_v1/examples/mcp/protocol_eras.py:50-58 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `libs/langchain_v1/examples/mcp/protocol_eras.py:50` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 8) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1192— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1192-1199 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1255-1262 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1302-1309 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1324-1331 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1535-1542 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1620-1627 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1641-1648 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1666-1673 — all 8 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1263` calls `write` and `libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:1201` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (7–8 lines × 2) libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:170— libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:170-176 | libs/standard-tests/langchain_tests/integration_tests/sandboxes.py:189-196 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Off the main sequence: langchain-core — langchain-core: abstractness 0.13, instability 0.00, distance 0.87 — zone of pain — concrete and depended on by 20 project(s), so it's rigid to change.
P8 · Schema migrations· Schema created by SQLAlchemy create_all() (no migration path) · ×1
Schema created by SQLAlchemy create_all() (no migration path) libs/langchain/langchain_classic/indexes/_sql_record_manager.py:154— SQLAlchemy create_all() builds the schema from the model at startup and keeps no migration history, so there is no reviewed, repeatable upgrade path for an existing production database — a renamed column is dropped and re-added rather than migrated. Adopt Alembic (`alembic revision --autogenerate` + `alembic upgrade head`), so every schema change is a versioned file applied the same way in every environment.
X28 · Index access outside its own emptiness guard· Index access outside its own emptiness guard · ×1
Index access outside its own emptiness guard libs/core/langchain_core/prompts/structured.py:203— This condition tests `others` for emptiness and then indexes it on a branch that test does not reach. `others[0]` is evaluated whenever the guarded half is false — which includes the case the guard exists to anticipate, `others` being empty — so an empty `others` indexes position 0 of nothing and throws. This same condition already shows the intended bracketing at line 202: `others[0]` sits INSIDE the guard. Either the guard is load-bearing, in which case this access escapes it and crashes, or `others` cannot be empty here, in which case the guard beside it is dead code — the condition is wrong under both readings. Move the parenthesis so the emptiness test brackets every access to `others`.
Orphaned file libs/langchain/langchain_classic/llms/__init__.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/sql_database/prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/__init__.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/question_answering/chain.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/qa_with_sources/base.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/summarize/chain.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/memory/prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/question_answering/map_reduce_prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/vectorstores/__init__.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/qa_with_sources/loading.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/qa_with_sources/map_reduce_prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/query_constructor/prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/core/langchain_core/tracers/stdout.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/qa_with_sources/stuff_prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/agents/react/base.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/agents/conversational_chat/base.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/agents/react/wiki_prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/agents/conversational/base.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/memory/summary_buffer.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/core/langchain_core/output_parsers/transform.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/evaluation/__init__.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/chains/natbot/prompt.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/partners/anthropic/langchain_anthropic/experimental.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file libs/langchain/langchain_classic/retrievers/document_compressors/chain_extract.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Duplicated predicate libs/core/langchain_core/messages/block_translators/openai.py:42— `"base64" in block or block.get("source_type") == "base64"` appears character-identically in 3 files — libs/core/langchain_core/messages/block_translators/openai.py, libs/partners/anthropic/langchain_anthropic/chat_models.py, libs/partners/openrouter/langchain_openrouter/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:215— `"file_id" in block or block.get("source_type") == "id"` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/partners/typesafe/langchain_typesafe/_assets.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/langchain/langchain_classic/chains/llm_math/base.py:185— `"llm_chain" not in values and values["llm"] is not None` appears character-identically in 2 files — libs/langchain/langchain_classic/chains/llm_math/base.py, libs/langchain/langchain_classic/chains/natbot/base.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1604— `"max_tokens" in kwargs and isinstance(kwargs["max_tokens"], int)` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1588— `"model" in kwargs and isinstance(kwargs["model"], str)` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:577— `"name" in function_call and function_call["name"] is None` appears character-identically in 5 files — REDACTED, libs/partners/groq/langchain_groq/chat_models.py, libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py, libs/partners/openai/langchain_openai/chat_models/base.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1596— `"temperature" in kwargs and isinstance(kwargs["temperature"], (int, float))` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:439— `"tool_calls" in message_dict and message_dict["content"] == ""` appears character-identically in 2 files — REDACTED, libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/partners/openai/langchain_openai/chat_models/base.py:4626— `"type" in tool and tool["type"] != "function"` appears character-identically in 2 files — libs/partners/openai/langchain_openai/chat_models/base.py, libs/partners/perplexity/langchain_perplexity/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/partners/anthropic/langchain_anthropic/chat_models.py:1748— `_get_default_model_profile(self.model) or None` appears character-identically in 3 files — libs/partners/anthropic/langchain_anthropic/chat_models.py, libs/partners/mistralai/langchain_mistralai/chat_models.py, libs/partners/perplexity/langchain_perplexity/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/partners/deepseek/langchain_deepseek/chat_models.py:357— `_get_default_model_profile(self.model_name) or None` appears character-identically in 7 files — libs/partners/deepseek/langchain_deepseek/chat_models.py, REDACTED, libs/partners/groq/langchain_groq/chat_models.py, libs/partners/openai/langchain_openai/chat_models/azure.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/messages/block_translators/openai.py:94— `block.get("source_type") == "base64" or "base64" in block` appears character-identically in 2 files — libs/core/langchain_core/messages/block_translators/openai.py, libs/partners/openrouter/langchain_openrouter/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/messages/block_translators/openai.py:119— `block.get("source_type") == "id" or "file_id" in block` appears character-identically in 2 files — libs/core/langchain_core/messages/block_translators/openai.py, libs/partners/openrouter/langchain_openrouter/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/messages/base.py:286— `block.get("type") == "text" and isinstance(block.get("text"), str)` appears character-identically in 2 files — libs/core/langchain_core/messages/base.py, libs/partners/mistralai/langchain_mistralai/_compat.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/partners/mistralai/langchain_mistralai/_compat.py:125— `block.get("type") == "thinking" and isinstance( block.get("thinking"), list )` appears character-identically in 2 files — libs/partners/mistralai/langchain_mistralai/_compat.py, libs/partners/mistralai/langchain_mistralai/chat_models.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/langchain/langchain_classic/chat_models/base.py:833— `config is None or isinstance(config, dict) or len(config) <= 1` appears character-identically in 2 files — libs/langchain/langchain_classic/chat_models/base.py, libs/langchain_v1/langchain/chat_models/base.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/retrievers.py:216— `config.get("run_name") or self.get_name()` appears character-identically in 7 files — libs/core/langchain_core/retrievers.py, libs/core/langchain_core/runnables/base.py, libs/core/langchain_core/runnables/branch.py, libs/core/langchain_core/runnables/fallbacks.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/langchain/langchain_classic/chat_models/base.py:683— `config_prefix and not config_prefix.endswith("_")` appears character-identically in 2 files — libs/langchain/langchain_classic/chat_models/base.py, libs/langchain_v1/langchain/chat_models/base.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/langchain/langchain_classic/chat_models/base.py:364— `config_prefix and not configurable_fields` appears character-identically in 2 files — libs/langchain/langchain_classic/chat_models/base.py, libs/langchain_v1/langchain/chat_models/base.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/prompts/few_shot.py:75— `examples is None and example_selector is None` appears character-identically in 2 files — libs/core/langchain_core/prompts/few_shot.py, libs/core/langchain_core/prompts/few_shot_with_templates.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1606— `hasattr(self, "max_tokens") and isinstance(self.max_tokens, int)` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1590— `hasattr(self, "model") and isinstance(self.model, str)` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1592— `hasattr(self, "model_name") and isinstance(self.model_name, str)` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/core/langchain_core/language_models/chat_models.py:1598— `hasattr(self, "temperature") and isinstance( self.temperature, (int, float) )` appears character-identically in 2 files — libs/core/langchain_core/language_models/chat_models.py, libs/core/langchain_core/language_models/llms.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate libs/langchain_v1/langchain/agents/middleware/file_search.py:241— `include and not _is_valid_include_pattern(include)` appears character-identically in 2 files — libs/langchain_v1/langchain/agents/middleware/file_search.py, libs/partners/anthropic/langchain_anthropic/middleware/file_search.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Silent fallback default on parse failure libs/core/langchain_core/runnables/utils.py:448— `get_function_nonlocals` returns `[]` when `(SyntaxError, TypeError, OSError, SystemError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure libs/langchain_v1/langchain/agents/middleware/file_search.py:175— `glob_search` (in `__init__`) returns `'No files found'` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure libs/langchain_v1/langchain/agents/middleware/file_search.py:298— `_ripgrep_search` returns `{}` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure libs/langchain_v1/langchain/agents/middleware/file_search.py:355— `_python_search` returns `{}` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Interpolated log message defeats structured logging libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py:309— `warning` at line 309 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py:231— `warning` at line 231 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Off-boarding risk: anonymized user #1 — If anonymized user #1 becomes unavailable, 3 significant file(s) lose their only recent owner: libs/model-profiles/langchain_model_profiles/_summary.py, libs/partners/fireworks/langchain_fireworks/middleware/prompt_caching.py, libs/standard-tests/langchain_tests/_langsmith_plugin.py. Pair on, review, or document these before any departure.
D16 · Bus Factor· Further sole-owners (lower concentration) · ×1
Further sole-owners (lower concentration) — 4 other contributor(s) are each the sole owner of a small amount of code below the off-boarding threshold — folded into the bus-factor score and metrics (7 single-owned of 446 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 446 of the 1766 production source files in this repository met that bar). They are anonymized user #2 (1 file(s)), anonymized user #3 (1 file(s)), anonymized user #4 (1 file(s)), anonymized user #5 (1 file(s)) — spread or document their files in the same way, at lower priority than the named off-boarding risks above. The files folded here: libs/partners/typesafe/langchain_typesafe/client.py, libs/langchain_v1/langchain/agents/_subagent_transformer.py, libs/langchain_v1/langchain/agents/middleware/tool_error.py, libs/langchain_v1/langchain/agents/middleware/internal_call_transformer.py.
No ADRs found REDACTED:50— No ADRs found. The recognised ADR directories in this tree were read — `libs/core/langchain_core/decisions`, `libs/core/tests/unit_tests/decisions`, `libs/partners/openai/langchain_openai/decisions`, `libs/partners/openai/tests/integration_tests/decisions`, `libs/partners/openai/tests/unit_tests/decisions` — and none of their files is a decision record (a README, index or template page does not count). What was searched, so you can tell an empty log from a search that missed one: every directory under the tree (build output, dependencies and VCS metadata excepted), for a document that is either any non-index page inside a recognised ADR directory, whatever its name and however deeply nested (`docs/adr/use-postgres.md`, `docs/adr/2024/0001-x.md`); or a file anywhere whose name is ADR-shaped (`0001-use-postgres.md`, `adr-012-caching.md`); or, when neither turned anything up, a document carrying the decision-record signature (an "Architecture Decision Record" heading, or Status / Context / Decision / Consequences as section headings). A decision log that clears none of these — unnumbered files outside any recognised directory, without those headings — is not seen by this check and this row is then wrong. If that is your case, say so rather than renaming anything; otherwise, consider recording architectural decisions in `docs/adr/`. ADRs are expected here because `REDACTED` makes this repository a deployable product (line 50).
D26 · Project Cohesion· Projects may be oversized for their cohesion · ×1
Projects may be oversized for their cohesion — 3 of 22 project(s) overshoot their size bounds, lowering Project Cohesion to 7.3/10. The most over is `libs/langchain` (57113 LoC, 1196 module-visible types across 186 directories). Review these for cohesion — draw the boundary inside the module first (group each responsibility into its own package or directory and keep the cross-boundary members non-public), since splitting a published package moves types between packages and breaks consumers.
D28 · Secrets (history)· Rotate the exposed credentials · ×1
REDACTED
D34 · Knowledge Freshness· Further orphaned files (smaller) · ×1
Further orphaned files (smaller) — 57 smaller file(s) also have no living knowledge — folded into the freshness score and metrics rather than raised one row each — most significant first: libs/langchain/langchain_classic/llms/__init__.py, libs/langchain/langchain_classic/chains/sql_database/prompt.py, libs/langchain/langchain_classic/__init__.py, libs/langchain/langchain_classic/chains/question_answering/chain.py, libs/langchain/langchain_classic/chains/qa_with_sources/base.py, libs/langchain/langchain_classic/chains/summarize/chain.py, libs/langchain/langchain_classic/memory/prompt.py, libs/langchain/langchain_classic/chains/question_answering/map_reduce_prompt.py (and 49 more) (58 orphaned of 446 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 446 of the 1766 production source files in this repository met that bar). Attach the read to the next change that touches one of them: have a second person review that change, and leave behind a short comment or test recording what the file is for, so the knowledge comes back at the cost of a change you were making anyway.
No ADRs — No Architecture Decision Records found — no conventional ADR directory, no numbered `NNNN-title` documents in any markup this check reads, and nothing ADR-shaped by content. Design rationale recorded elsewhere (a design-notes tree, a mailing list, pull-request discussion) is not visible to this check and is not re-findable per decision, so a future maintainer cannot ask why one choice was made and get an answer.
Logging is not universal — Only 12/13 runnable modules use logging (modules with no entry point or server are excluded — they are libraries a runnable module hosts). Silent: `libs/model-profiles`.
No SAST .github/workflows/block_fork_main_prs.yml:18— No static application security testing detected. For this repository's stack, add bandit, `semgrep --config=p/python`, or CodeQL's python pack as a CI step. What was searched, so you can tell an absence from a miss: the 27 CI workflow file(s) in this repository, and the scanner and linter configuration checked in beside them. A scan that runs outside CI, one configured in your forge's web UI rather than in a committed file, or a tool whose name is none of those this check carries, is not seen — if that is your case the row is wrong, and saying so is more useful than adding a second scanner.
No changelog — No CHANGELOG/HISTORY/RELEASES file — what shipped when isn't easy to reconstruct for support or audit. (Versioning/tagging makes releases traceable, but a changelog records the what.)
X23 · Unguarded diagnostic materialisation· Diagnostic log message is built whether or not it is wanted · ×1
Diagnostic log message is built whether or not it is wanted libs/langchain_v1/langchain/agents/middleware/model_fallback.py:161— `debug` at line 161 is called with an argument built by `sorted(overrides)` (line 163), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Hand-rolled JSON/XML parsing via regex libs/core/langchain_core/messages/block_translators/groq.py:41— A regex whose pattern encodes JSON/XML syntax is parsing a structured format by hand — malformed or differently-typed content (e.g. `"amount": "5"` as a string) silently mis-parses instead of failing validation. This Python code already uses a real parser in the same package; use it here too.
Silent fallback default in catch libs/core/langchain_core/language_models/_compat_bridge.py:153— `_iter_protocol_blocks` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Appendix B — Reproduction & audit trail
Every external tool invocation behind a deep-scan dimension — the tool, its captured version, the exact command, how many findings it yielded, and a link to the retained raw output. To reproduce any finding: check out the same commit and run the command shown (repo-relative — never an absolute scratch path). The complete raw scanner output is retained verbatim under artifacts/raw/ (indexed in artifacts/raw/index.json); per-invocation exit codes and wall-clock durations are in sidecar.json — kept out of this table so the rendered report stays byte-identical across runs of the same commit.
semgrep: not applicable — No personal data was found crossing a boundary the PII/GDPR ruleset checks — nothing written to a log or console sink, placed in a URL or query string, or persisted to browser storage. That is a clean result for the LEAK surface only: this ruleset detects personal data escaping, it does not inventory the personal data a repository holds, so it is not evidence that this repository has no personal-data surface. The personal-data map (Appendix C) and the C1-C5 compliance cards are what speak to that.
disclosure: not applicable — No vulnerability-disclosure policy file found (SECURITY.md/.markdown/.rst/.txt at root or under .github/.forgejo/.gitea/docs, .well-known/security.txt). A coordinated-disclosure policy may live off-repo, so this is not evidenced rather than failed.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
Run 01a1d78d-4fa5-7db6-bb6c-2721aedda343 · every finding is also locatable in findings.md, and the complete scoring record (with exit codes + durations) in sidecar.json.
Issues: 49 · Warnings: 1300 · Recommendations: 120 — Appendix A · all findings · full markdown report.
Generated by the Canine Code Analyzer: deterministic code-health analysis. 14-11-2026 @ 00:55 UTC.
Downloadable artifacts
Machine-readable and reproducible from this commit + frozen rubric — drop them straight into a contract appendix, a CRA dossier, or a downstream SCA / VEX tool.