iflytek/astron-agent · error · ValueError

When mode=0 (CUSTOM), sql is required and must not be empty.

Error message

When mode=0 (CUSTOM), sql is required and must not be empty.

What it means

Pydantic field validator on the PGSQL node's `sql` field. In CUSTOM mode (mode=0) the user must supply raw SQL; if `sql` is None or blank the model refuses to construct and raises a ValueError that surfaces as a pydantic ValidationError.

Solutions

  1. Provide a non-empty `sql` string in the node config when mode=0.
  2. If the user intends table-driven operations, switch mode to 1 (INSERT), 2 (UPDATE), 3 (SELECT), or 4 (DELETE) instead of CUSTOM.
  3. Fix the frontend/workflow editor to disable saving CUSTOM-mode nodes until SQL is entered.
  4. Catch the pydantic ValidationError at workflow-import time and show a field-level message pointing at `sql`.

Example fix

// before
node_data = PgsqlNodeData(mode=0, sql="")
// after
node_data = PgsqlNodeData(mode=0, sql="SELECT * FROM users WHERE id = :id")
Defensive patterns

Strategy: validation

Validate before calling

def validate_custom_sql(node_cfg: dict):
    if node_cfg.get("mode") == 0 and not (node_cfg.get("sql") or "").strip():
        raise ValueError("mode=0 requires a non-empty sql")

Type guard

def has_custom_sql(cfg) -> bool:
    return not (cfg.mode == 0 and (cfg.sql is None or not cfg.sql.strip()))

Try / catch

try:
    node_data = PgsqlNodeData(**cfg)
except ValidationError as e:
    for err in e.errors():
        if "mode=0 (CUSTOM)" in err["msg"]:
            show_field_error("sql", "Custom SQL is required")
    raise

Prevention

When it happens

Trigger: Constructing PgsqlNodeData (or parsing the node config) with `mode: 0` and `sql` missing, empty string, or whitespace-only.

Common situations: Workflow author leaves the SQL editor empty in CUSTOM mode; frontend sends default/empty sql; importing a workflow JSON where the sql field was dropped.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/fbb07a5cca0a7e76. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/engine/nodes/pgsql/pgsql_node.py:111

    sql: str | None = Field(default=None, min_length=1)  # Raw SQL for CUSTOM mode
    cases: List[Case] = Field(default_factory=list)  # WHERE conditions
    assignmentList: List[AssignmentType] = Field(default_factory=list)  # type: ignore # Columns for SELECT/UPDATE
    orderData: List[OrderItem] = Field(default_factory=list)  # ORDER BY configuration
    limit: int = Field(default=0, ge=0)  # LIMIT clause for SELECT

    # --- conditional validation ---
    @field_validator("sql", mode="after")
    def _check_custom_sql(cls, v: str | None, info: ValidationInfo) -> str | None:
        """
        Check if the SQL is valid for CUSTOM mode.

        :param v: SQL string
        :param info: ValidationInfo
        :return: SQL string
        :raises ValueError: If the SQL is invalid
        """
        if info.data.get("mode") == 0 and (v is None or v.strip() == ""):
            raise ValueError(
                "When mode=0 (CUSTOM), sql is required and must not be empty."
            )
        return v

    @field_validator("tableName", mode="after")
    def _check_table_name(cls, v: str | None, info: ValidationInfo) -> str | None:
        """
        Check if the table name is valid for the given mode.

        :param v: Table name string
        :param info: ValidationInfo
        :return: Table name string
        :raises ValueError: If the table name is invalid
        """
        mode = info.data.get("mode")
        if mode in (1, 2, 3, 4) and (v is None or v.strip() == ""):
            raise ValueError(f"When mode={mode}, tableName is required.")
        return v

View on GitHub (pinned to 5e758547a8)