Back Home

GitHub Repo

Dify Proposes Agent v2 Numeric Validation Fix to Prevent NaN and Infinity from Being Treated as Successful Outputs

On November 14, the Dify community reported that Agent v2 accepts NaN and positive or negative infinity as valid numbers, allowing nodes to bypass existing failure handling. A fix with regression tests has been proposed but not merged; its impact on released versions remains to be confirmed.

The original uploader was Ggia at Greek Wikipedia. · CC BY-SA 2.5 · Image source
zh-Hant

On November 14, the Dify community reported an output validation issue in Agent v2: when a workflow declares a numeric field named score, the node still reports success even if the backend returns NaN, positive infinity, or negative infinity. The report targets source revision 05f3723 and injects results through an existing backend test double; it is not an incident report involving an actual model service. Issue report

The gap is in the numeric type check. The existing code confirms that a result is a Python integer or floating-point number and excludes booleans, but does not check whether floating-point values are finite. As a result, NaN and infinity pass validation. For workflows that rely on agent scoring, calculations, or structured output, this means that “node success” alone does not guarantee that a number is usable downstream. This is an engineering risk inferred from the validation behavior; the report does not provide an example of production impact. Proposed diff

This also affects data exchange between services. The Python documentation explains that the standard library’s JSON encoder permits NaN and Infinity by default, even though these values do not conform to the strict JSON specification. Setting allow_nan=False raises an error during serialization. Therefore, the ability to encode a value in Python does not mean other services can accept it. If engineering teams check only the type, they may discover incompatible numbers only at a later API boundary. Python JSON documentation

PR #46348, submitted the same day, adds a math.isfinite check so that non-finite floating-point values go through the existing output type failure handling. New tests inject each of the three values and require the node to report output_type_check_failed. The submitter said that 91 tests across the two relevant test files passed; two Windows tracing failures occurred in a broader test run and were also reproducible with the original checker. Proposed fix

As of the time of review, the proposal had not been merged, and no release containing the fix had been confirmed. Teams using numeric outputs from Agent v2 can add boundary checks for finiteness and downstream JSON compatibility, and track the merge status and whether their deployed version includes the relevant code.

Sources

  1. Agent v2 accepts non-finite values as successful number outputs — Issue #46347
  2. fix(workflow): reject non-finite Agent v2 number outputs — PR #46348
  3. PR #46348 — Files changed
  4. json — JSON encoder and decoder