langchain - ✅(Solved) Fix Fix typo in Visitor._validate_func error message for operators [10 pull requests, 5 comments, 5 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#36701Fetched 2026-04-15 06:19:54
View on GitHub
Comments
5
Participants
5
Timeline
24
Reactions
0
Author
Timeline (top)
cross-referenced ×6commented ×5referenced ×5labeled ×3

In Visitor._validate_func (langchain_core/structured_query.py), when an invalid operator is passed, the error message incorrectly says "Allowed comparators are ..." instead of "Allowed operators are ...".

This is a copy-paste typo. The message should say "operators" to match what is actually being validated.

The typo is on line 32: https://github.com/langchain-ai/langchain/blob/8182d6302dc81bc62849f9aa88ff698489b0e665/libs/core/langchain_core/structured_query.py#L31-L32

Error Message

ValueError: Received disallowed operator Operator.OR. Allowed comparators are (Operator.AND,)

Root Cause

In Visitor._validate_func (langchain_core/structured_query.py), when an invalid operator is passed, the error message incorrectly says "Allowed comparators are ..." instead of "Allowed operators are ...".

This is a copy-paste typo. The message should say "operators" to match what is actually being validated.

The typo is on line 32: https://github.com/langchain-ai/langchain/blob/8182d6302dc81bc62849f9aa88ff698489b0e665/libs/core/langchain_core/structured_query.py#L31-L32

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.

PR fix notes

PR #36713: fix(core): correct typo in Visitor._validate_func error message

Description (problem / solution / changelog)

Fixes #36701

Changes

Changed "comparators" to "operators" in the error message for the operator validation branch of in .

When an invalid operator was passed, the error message incorrectly said:

Received disallowed operator Operator.OR. Allowed comparators are (Operator.AND,)

It should say:

Received disallowed operator Operator.OR. Allowed operators are (Operator.AND,)

This is a one-word fix for a copy-paste typo.


This contribution was made with AI agent assistance.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36723: fix: typo in Visitor error msg, Blob.as_bytes_io string support, batch_size validation

Description (problem / solution / changelog)

Summary

Fix 1 — Typo in Visitor._validate_func error message (fixes #36701)

The error message for disallowed operators said 'Allowed comparators are...' instead of 'Allowed operators are...'. Fixed the incorrect word.

Fix 2 — Blob.as_bytes_io() raises NotImplementedError for string data (fixes #36667)

When blob.data is a str, the method raised NotImplementedError. Now encodes the string to UTF-8 bytes and yields a BytesIO object, consistent with the bytes branch.

Fix 3 — _batch/_abatch missing batch_size validation (fixes #36647)

When batch_size <= 0 was passed, both functions would loop infinitely. Added a guard at the top of each:

if size <= 0:
    raise ValueError("batch_size must be a positive integer")

Changed files

  • libs/core/langchain_core/documents/base.py (modified, +2/-0)
  • libs/core/langchain_core/indexing/api.py (modified, +4/-0)
  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36731: fix: correct error message in Visitor._validate_func (typo)

Description (problem / solution / changelog)

Good day,

I noticed a small typo in the Visitor._validate_func method in langchain_core/structured_query.py. The error message incorrectly says 'Allowed comparators' when validating operators, but it should say 'Allowed operators'.

Before: Received disallowed operator X. Allowed comparators are Y

After: Received disallowed operator X. Allowed operators are Y

This is similar to issue #36701 which reported this bug.

Thank you for your work on this project. I hope this small fix is helpful. Please let me know if there's anything to adjust.

Warmly, RoomWithOutRoof

Changed files

  • libs/core/langchain_core/runnables/fallbacks.py (modified, +2/-2)
  • libs/core/langchain_core/structured_query.py (modified, +1/-1)
  • libs/core/langchain_core/utils/_merge.py (modified, +1/-1)
  • libs/core/langchain_core/utils/usage.py (modified, +3/-3)

PR #36733: fix(core): correct error message typo in Visitor._validate_func

Description (problem / solution / changelog)

Description

Fixed a typo in the error message for disallowed operators in Visitor._validate_func (langchain_core/structured_query.py:32). Changed "comparators" to "operators" to match the actual variable self.allowed_operators being referenced.

Before:

f"Received disallowed operator {func}. Allowed "
f"comparators are {self.allowed_operators}"

After:

f"Received disallowed operator {func}. Allowed "
f"operators are {self.allowed_operators}"

Why

The error message incorrectly says "Allowed comparators are" when validating operators, which is confusing since the variable is self.allowed_operators. This is a copy-paste typo from the similar comparator validation logic above.

Testing

  • Existing tests continue to pass
  • The error message now correctly references "operators" instead of "comparators"

Fixes #36701


AI assistance disclaimer: AI assistance was used to help identify this issue and draft the initial fix. The final changes and test coverage were reviewed manually.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36737: fix: correct error message in Visitor._validate_func for operators

Description (problem / solution / changelog)

Summary

Fixes a copy-paste typo in Visitor._validate_func where the error message for disallowed operators incorrectly says "Allowed comparators are" instead of "Allowed operators are".

Changes

  • libs/core/langchain_core/structured_query.py: Changed "comparators" to "operators" in the error message for operator validation (line 32).

Testing

  • Verified the change is a single-word fix in an error message string.
  • No functional code changes; error message now correctly describes what is being validated.

Fixes #36701

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36738: fix(core): correct typo in Visitor._validate_func error message

Description (problem / solution / changelog)

Fixes #36701

Corrects a copy-paste typo in Visitor._validate_func: the operator branch incorrectly said "Allowed comparators are" instead of "Allowed operators are", making the error message misleading when an invalid operator was passed.

One-line change in libs/core/langchain_core/structured_query.py line 32.

Tests added in libs/core/tests/unit_tests/test_structured_query.py — covers both branches (operator and comparator), verifying the correct word appears in the error message.

How I verified it works

Ran the new tests locally against the patched file — all 4 pass. Also confirmed the original broken message ("Allowed comparators are" for an operator error) no longer appears.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)
  • libs/core/tests/unit_tests/test_structured_query.py (added, +52/-0)

PR #36743: core: fix "comparators" -> "operators" in Visitor._validate_func error message

Description (problem / solution / changelog)

Summary

Visitor._validate_func in libs/core/langchain_core/structured_query.py has two branches — one for Operator, one for Comparator. The error messages were originally copy-pasted and the operator branch still says comparators:

msg = (
    f"Received disallowed operator {func}. Allowed "
    f"comparators are {self.allowed_operators}"   # wrong noun
)

So when a custom visitor restricts operators and an unsupported one is passed, the raised ValueError reads like this:

ValueError: Received disallowed operator Operator.OR. Allowed comparators are (Operator.AND,)

…which is self-contradictory (two different nouns for the same thing) and confusing to anyone implementing a custom Visitor.

One-word fix: comparatorsoperators on L32. The Comparator branch a few lines below is already correct.

Fixes #36701

Test plan

  • Single-word edit, no behavior change
  • The Comparator branch (L41) unchanged — still says "comparators" as it should
  • Existing tests in libs/core/tests/unit_tests/ for structured_query continue to pass (CI will verify)

Base branch

Targeting master — happy to retarget if maintainers prefer a different base.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36757: Fix typo in Visitor._validate_func error message for operators

Description (problem / solution / changelog)

Description

In Visitor._validate_func (libs/core/langchain_core/structured_query.py), when validating an Operator against allowed_operators, the error message incorrectly says:

"Allowed comparators are ..."

It should say:

"Allowed operators are ..."

This is a copy-paste typo — the message was copied from the Comparator validation branch below but the word "comparators" was not updated to "operators".

Fix

1 line changed: comparatorsoperators on line 32 of structured_query.py

Related Issue

Fixes #36701

Type of Change

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

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36758: fix(visitor): correct typo in _validate_func error message

Description (problem / solution / changelog)

Correct typo in Visitor._validate_func error message for operators. The error message had a typo that made it harder to understand. Fixes #36701.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

PR #36845: fix(core): correct typo structured_query.py

Description (problem / solution / changelog)

Fixes #36701

Fixed a typo in structured_query.py.

Changed files

  • libs/core/langchain_core/structured_query.py (modified, +1/-1)

Code Example

from langchain_core.structured_query import Visitor, Operator, Comparator

class TestVisitor(Visitor):
    allowed_comparators = (Comparator.EQ,)
    allowed_operators = (Operator.AND,)

    def visit_operation(self, operation):
        pass

    def visit_comparison(self, comparison):
        pass

    def visit_structured_query(self, structured_query):
        pass

v = TestVisitor()
# Trigger the error with an operator that is not in allowed_operators
v._validate_func(Operator.OR)

---

ValueError: Received disallowed operator Operator.OR. Allowed comparators are (Operator.AND,)
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

No response

Reproduction Steps / Example Code (Python)

from langchain_core.structured_query import Visitor, Operator, Comparator

class TestVisitor(Visitor):
    allowed_comparators = (Comparator.EQ,)
    allowed_operators = (Operator.AND,)

    def visit_operation(self, operation):
        pass

    def visit_comparison(self, comparison):
        pass

    def visit_structured_query(self, structured_query):
        pass

v = TestVisitor()
# Trigger the error with an operator that is not in allowed_operators
v._validate_func(Operator.OR)

Error Message and Stack Trace (if applicable)

ValueError: Received disallowed operator Operator.OR. Allowed comparators are (Operator.AND,)

Description

In Visitor._validate_func (langchain_core/structured_query.py), when an invalid operator is passed, the error message incorrectly says "Allowed comparators are ..." instead of "Allowed operators are ...".

This is a copy-paste typo. The message should say "operators" to match what is actually being validated.

The typo is on line 32: https://github.com/langchain-ai/langchain/blob/8182d6302dc81bc62849f9aa88ff698489b0e665/libs/core/langchain_core/structured_query.py#L31-L32

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:55 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T8132 Python Version: 3.12.11 (main, Jul 23 2025, 00:18:05) [Clang 20.1.4 ]

extent analysis

TL;DR

The error message in Visitor._validate_func should be corrected to say "Allowed operators are ..." instead of "Allowed comparators are ...".

Guidance

  • The issue is caused by a typo in the error message of Visitor._validate_func in langchain_core/structured_query.py.
  • To verify the fix, run the provided example code and check that the error message now correctly says "Allowed operators are ...".
  • The correction should be made on line 32 of structured_query.py.
  • After making the change, re-run the tests to ensure that the fix does not introduce any new issues.

Example

# Corrected code
def _validate_func(self, func):
    if func not in self.allowed_operators:
        raise ValueError(f"Received disallowed operator {func}. Allowed operators are {self.allowed_operators}")

Notes

This fix assumes that the only issue is the typo in the error message. If there are other problems with the code, additional changes may be necessary.

Recommendation

Apply workaround: Correct the typo in the error message to ensure that the correct information is displayed when an invalid operator is passed.

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