langchain - ✅(Solved) Fix Feature/Bug: Implement missing Language.PERL separators and fix InMemoryCache maxsize update bug [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36750Fetched 2026-04-17 08:23:03
View on GitHub
Comments
1
Participants
1
Timeline
7
Reactions
0
Participants
Timeline (top)
labeled ×4commented ×1cross-referenced ×1issue_type_added ×1

There are two distinct bugs grouped here:

  1. Language.PERL is correctly defined in the Language enum, but the switch statement inside get_separators_for_language does not handle it, resulting in a fall-through ValueError instead of appropriately fetching Perl-specific separators.
  2. InMemoryCache.update() shrinks the cache incorrectly. When the cache is at its exact maxsize, and you call update() using a key that already exists in the cache, the code checks len(cache) == maxsize and forcefully evicts the oldest entry anyway, lowering the cache size instead of performing an in-place update.

I have already pushed a Branch fixing both issues (adding Perl separators for sub, package, do, eval, etc., and adding an eviction safety guard for InMemoryCache) to my fork and am ready to raise the associated PR closing this issue!

Error Message

---- Bug 1: Language.PERL not implemented ----

from langchain_text_splitters import RecursiveCharacterTextSplitter, Language

try: # PERL exists in enum but is not implemented in separator logic RecursiveCharacterTextSplitter.from_language( Language.PERL, chunk_size=10, chunk_overlap=0 ) except ValueError as e: print(f"Bug 1 Error: {e}")

---- Bug 2: InMemoryCache eviction bug ----

from langchain_core.caches import InMemoryCache

cache = InMemoryCache(maxsize=2)

cache.update("prompt_1", "llm_1", "val1") cache.update("prompt_2", "llm_2", "val2")

Cache is now at maxsize.

Updating an existing key SHOULD NOT evict another entry.

cache.update("prompt_2", "llm_2", "val2_new_value")

Expected: prompt_1 still exists

print("Cache keys:", list(cache._cache.keys())) print("Bug 2: Is prompt_1 still in cache?", ("prompt_1", "llm_1") in cache._cache)

Root Cause

There are two distinct bugs grouped here:

  1. Language.PERL is correctly defined in the Language enum, but the switch statement inside get_separators_for_language does not handle it, resulting in a fall-through ValueError instead of appropriately fetching Perl-specific separators.
  2. InMemoryCache.update() shrinks the cache incorrectly. When the cache is at its exact maxsize, and you call update() using a key that already exists in the cache, the code checks len(cache) == maxsize and forcefully evicts the oldest entry anyway, lowering the cache size instead of performing an in-place update.

I have already pushed a Branch fixing both issues (adding Perl separators for sub, package, do, eval, etc., and adding an eviction safety guard for InMemoryCache) to my fork and am ready to raise the associated PR closing this issue!

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

aiohttp: 3.13.4 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.0.8 numpy: 2.4.4 openai: 2.30.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pydantic-settings: 2.13.1 pytest: 9.0.2 PyYAML: 6.0.3 pyyaml: 6.0.3 requests: 2.33.0 requests-toolbelt: 1.0.0 rich: 15.0.0 SQLAlchemy: 2.0.48 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36751: Feature/Bug: Implement missing Language.PERL separators and fix InMemoryCache maxsize update bug

Description (problem / solution / changelog)

Fixes #36750

Description

This PR addresses two separate issues:

  1. Missing Language.PERL implementation: Language.PERL was defined in the Language enum but had no separators in get_separators_for_language, causing it to throw a ValueError when used. This PR adds the correct perl-specific separators (sub, package, use, require, eval, and control flow words) along with a unit test.
  2. InMemoryCache.update eviction bug: When InMemoryCache reaches maxsize and you update an entry that already exists in the cache, the old code incorrectly evicted the first entry in the dictionary. It now specifically checks (prompt, llm_string) not in self._cache before triggering an eviction. We also added a regression test to prevent this bug in the future.

Changed files

  • libs/core/langchain_core/caches.py (modified, +5/-1)
  • libs/core/tests/unit_tests/caches/test_in_memory_cache.py (modified, +30/-0)
  • libs/text-splitters/langchain_text_splitters/character.py (modified, +26/-0)
  • libs/text-splitters/tests/unit_tests/test_text_splitters.py (modified, +30/-0)

Code Example

# ---- Bug 1: Language.PERL not implemented ----
from langchain_text_splitters import RecursiveCharacterTextSplitter, Language

try:
    # PERL exists in enum but is not implemented in separator logic
    RecursiveCharacterTextSplitter.from_language(
        Language.PERL,
        chunk_size=10,
        chunk_overlap=0
    )
except ValueError as e:
    print(f"Bug 1 Error: {e}")


# ---- Bug 2: InMemoryCache eviction bug ----
from langchain_core.caches import InMemoryCache

cache = InMemoryCache(maxsize=2)

cache.update("prompt_1", "llm_1", "val1")
cache.update("prompt_2", "llm_2", "val2")

# Cache is now at maxsize.
# Updating an existing key SHOULD NOT evict another entry.
cache.update("prompt_2", "llm_2", "val2_new_value")

# Expected: prompt_1 still exists
print("Cache keys:", list(cache._cache.keys()))
print("Bug 2: Is prompt_1 still in cache?",
      ("prompt_1", "llm_1") in cache._cache)

---

# Bug 1
ValueError: Language Language.PERL is not implemented yet!

# Bug 2 (Observed Behavior)
Bug 2: Is prompt_1 still in cache? False
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

N/A

Reproduction Steps / Example Code (Python)

# ---- Bug 1: Language.PERL not implemented ----
from langchain_text_splitters import RecursiveCharacterTextSplitter, Language

try:
    # PERL exists in enum but is not implemented in separator logic
    RecursiveCharacterTextSplitter.from_language(
        Language.PERL,
        chunk_size=10,
        chunk_overlap=0
    )
except ValueError as e:
    print(f"Bug 1 Error: {e}")


# ---- Bug 2: InMemoryCache eviction bug ----
from langchain_core.caches import InMemoryCache

cache = InMemoryCache(maxsize=2)

cache.update("prompt_1", "llm_1", "val1")
cache.update("prompt_2", "llm_2", "val2")

# Cache is now at maxsize.
# Updating an existing key SHOULD NOT evict another entry.
cache.update("prompt_2", "llm_2", "val2_new_value")

# Expected: prompt_1 still exists
print("Cache keys:", list(cache._cache.keys()))
print("Bug 2: Is prompt_1 still in cache?",
      ("prompt_1", "llm_1") in cache._cache)

Error Message and Stack Trace (if applicable)

# Bug 1
ValueError: Language Language.PERL is not implemented yet!

# Bug 2 (Observed Behavior)
Bug 2: Is prompt_1 still in cache? False

Description

There are two distinct bugs grouped here:

  1. Language.PERL is correctly defined in the Language enum, but the switch statement inside get_separators_for_language does not handle it, resulting in a fall-through ValueError instead of appropriately fetching Perl-specific separators.
  2. InMemoryCache.update() shrinks the cache incorrectly. When the cache is at its exact maxsize, and you call update() using a key that already exists in the cache, the code checks len(cache) == maxsize and forcefully evicts the oldest entry anyway, lowering the cache size instead of performing an in-place update.

I have already pushed a Branch fixing both issues (adding Perl separators for sub, package, do, eval, etc., and adding an eviction safety guard for InMemoryCache) to my fork and am ready to raise the associated PR closing this issue!

System Info

python3 -m langchain_core.sys_info /opt/homebrew/lib/python3.14/site-packages/langchain_core/_api/deprecation.py:25: UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater. from pydantic.v1.fields import FieldInfo as FieldInfoV1

System Information

OS: Darwin OS Version: Darwin Kernel Version 24.6.0: Wed Nov 5 21:33:59 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T8112 Python Version: 3.14.3 (main, Feb 3 2026, 15:32:20) [Clang 17.0.0 (clang-1700.6.3.2)]

Package Information

langchain_core: 1.2.11 langchain: 1.0.7 langchain_community: 0.3.31 langsmith: 0.7.22 langchain_openai: 1.0.3 langgraph_sdk: 0.3.12

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.13.4 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.0.8 numpy: 2.4.4 openai: 2.30.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pydantic-settings: 2.13.1 pytest: 9.0.2 PyYAML: 6.0.3 pyyaml: 6.0.3 requests: 2.33.0 requests-toolbelt: 1.0.0 rich: 15.0.0 SQLAlchemy: 2.0.48 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

TL;DR

The most likely fix for the reported bugs is to update the langchain-core and langchain-text-splitters packages with the fixes provided in the user's fork, which address the unimplemented Language.PERL and the InMemoryCache eviction bug.

Guidance

  1. Verify the bug fixes: Before merging the PR, verify that the fixes for Language.PERL and InMemoryCache work as expected by running the provided example code.
  2. Review the PR: Carefully review the PR to ensure that the changes are correct, complete, and do not introduce any new bugs.
  3. Test the updated packages: Thoroughly test the updated langchain-core and langchain-text-splitters packages to ensure that they work as expected and do not introduce any regressions.
  4. Check for compatibility: Verify that the updated packages are compatible with the user's Python version (3.14.3) and other dependencies.

Example

No code example is provided as the issue already includes a clear example of the bugs and the fixes are provided in the user's fork.

Notes

The user has already pushed a branch with the fixes, so the next step is to review and merge the PR. The fixes should be thoroughly tested to ensure they work as expected and do not introduce any new bugs.

Recommendation

Apply the workaround by merging the PR with the fixes provided in the user's fork, as it addresses the reported bugs and has already been tested by the user.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix Feature/Bug: Implement missing Language.PERL separators and fix InMemoryCache maxsize update bug [1 pull requests, 1 comments, 1 participants]