{
  "id": "python/pydantic-validation-error-bool-parsing",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings\ndebug\n  Input should be a valid boolean, unable to interpret input [type=bool_parsing, input_value='yes', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 设置模型验证错误：debug 字段无法解析为布尔值",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Settings\\\ndebug\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ boolean,\\ unable\\ to\\ interpret\\ input\\ \\[type=bool_parsing,\\ input_value='yes',\\ input_type=str\\]",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Pydantic v2 only accepts a limited set of boolean-like strings ('true','false','1','0','yes','no','on','off' are case-sensitive to specific forms). 'yes' is not accepted by default.",
  "root_cause_type": "generic",
  "root_cause_zh": "Pydantic v2 只接受有限形式的布尔字符串（'true'、'false'、'1'、'0'、'yes'、'no'、'on'、'off'，且对大小写敏感）。默认不接受 'yes'。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "bool('yes') returns True but bool('false') also returns True because any non-empty string is truthy.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "int('yes') raises ValueError immediately.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "from pydantic import BaseModel, field_validator\n\nclass Settings(BaseModel):\n    debug: bool\n\n    @field_validator('debug', mode='before')\n    @classmethod\n    def parse_bool(cls, v):\n        if isinstance(v, str):\n            return v.lower() in ('yes','true','1','on')\n        return v",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "data['debug'] = str(data['debug']).lower() in ('true','1','yes')",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}