infiniflow/ragflow · error · ValueError
Invoke JSON argument '{key}' is not JSON-serializable.
Error message
Invoke JSON argument '{key}' is not JSON-serializable. What it means
Thrown by the Invoke component when validating an argument passed as JSON. Before sending the request, the component runs json.dumps(value, allow_nan=False) on each argument; if the value cannot be serialized (TypeError) or contains NaN/Infinity (ValueError, because allow_nan=False), the argument is rejected. The original exception is chained, and a warning with the key, value type, and repr is logged.
Source
Thrown at agent/component/invoke.py:96
logging.info(
"Invoke JSON arg coercion skipped; value is not valid JSON. key=%s raw=%r error=%s",
key,
raw_value,
exc,
)
return raw_value
try:
json.dumps(value, allow_nan=False)
except (TypeError, ValueError) as exc:
logging.warning(
"Invoke JSON arg is not JSON-serializable. key=%s value_type=%s value=%r error=%s",
key,
type(value).__name__,
value,
exc,
)
raise ValueError(f"Invoke JSON argument '{key}' is not JSON-serializable.") from exc
return value
def get_input_form(self) -> dict[str, dict]:
res = {}
for item in self._param.variables or []:
if not isinstance(item, dict):
continue
ref = (item.get("ref") or "").strip()
if not ref or ref in res:
continue
elements = self.get_input_elements_from_text("{" + ref + "}")
element = elements.get(ref, {})
res[ref] = {
"type": "line",
"name": element.get("name") or item.get("key") or ref,
}View on GitHub (pinned to 554fb1133a)
Solutions
- Convert the offending value to JSON-native types before it reaches Invoke: str()/isoformat() for datetimes, list() for sets, .item() for numpy scalars, dict(model) for ORM rows.
- Check the preceding log line 'Invoke JSON arg is not JSON-serializable. key=... value_type=... value=...' to identify exactly which key and type failed, then fix that variable's producer.
- If NaN/Infinity is legitimate in your data, sanitize it explicitly (e.g. replace with None) because the component forbids non-finite floats by design.
- Add a Code/transform component between the producer and Invoke that normalizes the payload to plain dict/list/str/int/float/bool/None.
Example fix
# before
invoke_args = {"ts": created_at, "tags": {"a", "b"}} # datetime + set -> raises
# after
invoke_args = {
"ts": created_at.isoformat() if created_at else None,
"tags": sorted({"a", "b"}),
} Defensive patterns
Strategy: validation
Validate before calling
import json, math
def json_safe(value):
try:
json.dumps(value, allow_nan=False)
return True
except (TypeError, ValueError):
return False
# before wiring args into Invoke:
assert all(json_safe(v) for v in invoke_args.values()), invoke_args.keys() Type guard
import json
def is_json_serializable(v) -> bool:
try:
json.dumps(v, allow_nan=False)
return True
except (TypeError, ValueError):
return False Try / catch
try:
invoke_component._invoke(**kwargs)
except ValueError as e:
if 'not JSON-serializable' in str(e):
# normalize the offending variable and retry once
... Prevention
- Normalize upstream outputs (datetime -> isoformat, set -> list, numpy -> .item()) in a Code component before Invoke.
- Never feed floats that can be NaN/Inf into JSON arguments; replace with None explicitly.
- Log key and type when serialization fails so the offending producer is identifiable.
When it happens
Trigger: Calling an Invoke component whose variables resolve to a non-JSON value: a datetime/date object, set, bytes, numpy scalar, or an ORM/model instance; or a float that is NaN/Inf (allow_nan=False makes even json.dumps itself raise ValueError). The failure occurs at argument-validation time, before any HTTP request is made.
Common situations: Upstream component (e.g. Code, Iteration, LLM returning structured output parsed into Python objects) produces datetime or numpy types that flow into an Invoke argument; dividing float values that yield NaN; passing a Peewee model row instead of a plain dict.
Related errors
- Invoke headers must be a JSON object.
- flow.formatTypeError
- Login failed: invalid JSON response ({exc})
- {} must be an array, but its type is {}
- The input of List Operations should be an array.
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/c3393954dd1059bd.
Report an issue: GitHub.