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

Langchain-Typesafe: NaN/Infinity In State Or Criteria Crash Invoke With Uncaught ValueError From Httpx2 Internals

Passing non-finite floats (NaN, Infinity, -Infinity) in state or Choice.criteria causes TypeSafeClassifier.invoke to crash with an uncaught ValueError from httpx2's allow_nan=False JSON encoder, instead of serializing them as strings per the reference SDK contract or raising a documented actionable error.

highConfidence 95%Langchain-TypesafeVector StoresEmbeddingsChainsAffected V0.0.1a3

Origin Analysis

_serialize_state_value in langchain_typesafe/_state.py passes float values through unchanged; TypeSafeClassifier._payload then feeds the resulting dict to httpx2's client.post(json=...), where httpx2._content.encode_json uses allow_nan=False and raises ValueError. The _classify method only catches httpx2.TimeoutException and httpx2.HTTPError, so ValueError propagates as an uncaught library defect.
Install langchain-typesafe 0.0.1a3 and run: import httpx2 from langchain_typesafe.classifier import TypeSafeClassifier from langchain_typesafe.types import Choice client = httpx2.Client(transport=httpx2.MockTransport(lambda request: httpx2.Response(200, json={"model":"m","answers":{},"usage":{}}))) classifier = TypeSafeClassifier(api_key="sk-repro", client=client) # Path A: NaN in state classifier.invoke({"state": {"value": float("nan")}, "questions": {}}) # Path B: Infinity in criteria classifier.invoke({"state": "x", "questions": {"q": Choice(instructions="pick", choices={"a":"A","b":"B"}, criteria={"threshold": float("inf")})}})

Fixing Code Block

Edge Case Audit

This global function replacement affects all serialization paths and all threads. If the upstream API later changes its string representation for non-finite numbers, this patch may break. Use a feature flag or environment variable to toggle between string conversion and strict validation. Rollback: restore the original _serialize_state_value or revert the source change. In concurrent environments, monkeypatching should be done at import time to avoid race conditions.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state