{
  "id": "llm/langchain-output-parser-schema-mismatch",
  "signature": "OutputParserException: Parsing LLM output produced by 'PydanticOutputParser' failed. Error: 1 validation error for WeatherResponse\ntemperature\n  Input should be a valid number [type=float_type, input_value='72.5°F', input_type=str]",
  "signature_zh": "OutputParserException：解析由 'PydanticOutputParser' 生成的 LLM 输出失败。错误：WeatherResponse 的 1 个验证错误\ntemperature\n  输入应为有效数字 [type=float_type, input_value='72.5°F', input_type=str]",
  "regex": "OutputParserException: Parsing LLM output produced by 'PydanticOutputParser' failed\\. Error: \\d+ validation error for \\w+",
  "domain": "llm",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "LLM output contains extra non-numeric characters (e.g., units like '°F') that the Pydantic output parser cannot coerce into the expected numeric type.",
  "root_cause_type": "generic",
  "root_cause_zh": "LLM 输出包含额外的非数字字符（例如单位 '°F'），Pydantic 输出解析器无法将其强制转换为预期的数字类型。",
  "versions": [
    {
      "version": "langchain 0.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "langchain-openai 0.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "pydantic 2.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "GPT-4 Turbo",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Claude 3 Opus",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The issue is not randomness; the LLM is following its training to include units. Temperature 0 still produces units in many cases.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The output is complete but includes extra text; max_tokens does not affect the content format.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "LangChain's PydanticOutputParser does not use OpenAI's response_format internally; it parses arbitrary text output. The JSON mode may not be compatible with the parser's prompt template.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add a post-processing step to strip units before parsing. In code: `raw_output = llm_output.replace('°F', '').replace('°C', ''); parsed = parser.parse(raw_output)`.",
      "success_rate": 0.85,
      "how": "Add a post-processing step to strip units before parsing. In code: `raw_output = llm_output.replace('°F', '').replace('°C', ''); parsed = parser.parse(raw_output)`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a custom prompt that explicitly forbids units, e.g., 'Return temperature as a plain number without units like °F or °C.'",
      "success_rate": 0.8,
      "how": "Use a custom prompt that explicitly forbids units, e.g., 'Return temperature as a plain number without units like °F or °C.'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Switch to `JsonOutputParser` with a post-validation step using Pydantic, allowing more flexible parsing of numeric fields.",
      "success_rate": 0.75,
      "how": "Switch to `JsonOutputParser` with a post-validation step using Pydantic, allowing more flexible parsing of numeric fields.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在解析前添加后处理步骤以去除单位。代码示例：`raw_output = llm_output.replace('°F', '').replace('°C', ''); parsed = parser.parse(raw_output)`。",
    "使用明确禁止单位的自定义提示，例如 '将温度作为纯数字返回，不要包含 °F 或 °C 等单位。'",
    "切换到 `JsonOutputParser` 并结合 Pydantic 进行后验证，允许更灵活地解析数字字段。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://python.langchain.com/docs/modules/model_io/output_parsers/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2024-04-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}