AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

TypeSafeClassifier Sends Requests When Questions Is Empty

langchain-typesafe's TypeSafeClassifier does not validate that the 'questions' mapping is non-empty before making an HTTP request, causing invalid API calls and a regression from previous Pydantic-based validation.

highConfidence 90%LangChainAffected V0.0.1a3

Origin Analysis

ClassifierRequest is a TypedDict with no runtime validation; the previous Pydantic field min_length=1 constraint was removed when questions moved from constructor to invocation scope.
Create a TypeSafeClassifier with a mock HTTP transport. Invoke classifier with {"state": "...", "questions": {}}. Observe that the HTTP request is sent with an empty questions object, e.g., {'state': '...', 'model': '...', 'questions': {}}.

Fixing Code Block

Edge Case Audit

This validation only fires when invoke/ainvoke are called directly. If TypeSafeClassifier overrides batch/abatch with a custom implementation that bypasses invoke/ainvoke, empty questions may still be sent. Add the same check in any custom batch path. Also, performing validation after callbacks/tracing have started will create a failed traced run; to avoid that, call validation before `on_chain_start`. The change is backward-compatible for valid inputs and only rejects previously invalid empty mappings. Rollback: remove the added calls to `_validate_non_empty_questions`.

Ecosystem Topology