langgenius/dify · warning · ValueError

has_comment must be a boolean value

Error message

has_comment must be a boolean value

What it means

ValueError raised by the field_validator on FeedbackExportQuery.has_comment (message.py:108) when the incoming value is a string that is not a recognized boolean token. The validator accepts actual bools, None, and the strings 'true/1/yes/on' (true) and 'false/0/no/off' (false), case-insensitively; anything else is rejected and surfaced by Pydantic as a 422/400.

Source

Thrown at api/controllers/console/app/message.py:108

class FeedbackExportQuery(BaseModel):
    from_source: Literal["user", "admin"] | None = Field(default=None, description="Filter by feedback source")
    rating: Literal["like", "dislike"] | None = Field(default=None, description="Filter by rating")
    has_comment: bool | None = Field(default=None, description="Only include feedback with comments")
    start_date: str | None = Field(default=None, description="Start date (YYYY-MM-DD)")
    end_date: str | None = Field(default=None, description="End date (YYYY-MM-DD)")
    format: Literal["csv", "json"] = Field(default="csv", description="Export format")

    @field_validator("has_comment", mode="before")
    @classmethod
    def parse_bool(cls, value: bool | str | None) -> bool | None:
        if isinstance(value, bool) or value is None:
            return value
        lowered = value.lower()
        if lowered in {"true", "1", "yes", "on"}:
            return True
        if lowered in {"false", "0", "no", "off"}:
            return False
        raise ValueError("has_comment must be a boolean value")


class AnnotationCountResponse(ResponseModel):
    count: int = Field(description="Number of annotations")


class SuggestedQuestionsResponse(ResponseModel):
    data: list[str] = Field(description="Suggested question")


class MessageDetailResponse(BaseMessageDetailResponse):
    extra_contents: list[ExecutionExtraContentDomainModel] = Field(default_factory=list)


class MessageInfiniteScrollPaginationResponse(ResponseModel):
    limit: int
    has_more: bool
    data: list[MessageDetailResponse]

View on GitHub (pinned to ef8544b173)

Solutions

  1. Send has_comment as a standard boolean string: 'true'/'false', '1'/'0', 'yes'/'no', or 'on'/'off'.
  2. Omit the param entirely if you do not want to filter by comment presence.
  3. If your client only emits 'y'/'n', preprocess to 'true'/'false' before calling.

Example fix

// before
GET /message/feedback/export?has_comment=maybe
// after
GET /message/feedback/export?has_comment=true
Defensive patterns

Strategy: validation

Validate before calling

const TRUTHY = new Set(['true', '1', 'yes', 'on']);
const FALSY = new Set(['false', '0', 'no', 'off']);
function normalizeHasComment(v: string | boolean | null): boolean | null {
  if (v === null || typeof v === 'boolean') return v;
  const l = String(v).toLowerCase();
  if (TRUTHY.has(l)) return true;
  if (FALSY.has(l)) return false;
  throw new Error(`has_comment must be one of true|false|1|0|yes|no|on|off, got ${v}`);
}

Type guard

function isAcceptedBoolString(v: string): boolean {
  const l = v.toLowerCase();
  return ['true','1','yes','on','false','0','no','off'].includes(l);
}

Prevention

When it happens

Trigger: GET /console/api/apps/<app_id>/message/feedback/export with a has_comment query param whose value is not a recognized boolean string (e.g. has_comment=maybe, has_comment=y, has_comment=2).

Common situations: Client using shorthand like 'y'/'n' or 't'/'f'; copy-pasted URL with a wrong value; localization producing non-English words.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/5f4c5d3110704658. Report an issue: GitHub.