{
  "canonical_name": "567-labs/instructor",
  "compilation_id": "pack_cafa3d566843424786fcf625233e19b8",
  "created_at": "2026-05-16T06:24:49.676151+00:00",
  "created_by": "project-pack-compiler",
  "feedback": {
    "carrier_selection_notes": [
      "viable_asset_types=skill, recipe, host_instruction, eval, preflight",
      "recommended_asset_types=skill, recipe, host_instruction, eval, preflight"
    ],
    "evidence_delta": {
      "confirmed_claims": [
        "identity_anchor_present",
        "capability_and_host_targets_present",
        "install_path_declared_or_better"
      ],
      "missing_required_fields": [],
      "must_verify_forwarded": [
        "Run or inspect `pip install instructor` in an isolated environment.",
        "Confirm the project exposes the claimed capability to at least one target host."
      ],
      "quickstart_execution_scope": "allowlisted_sandbox_smoke",
      "sandbox_command": "pip install instructor",
      "sandbox_container_image": "python:3.12-slim",
      "sandbox_execution_backend": "docker",
      "sandbox_planner_decision": "llm_execute_isolated_install",
      "sandbox_validation_id": "sbx_bc8f33535fcf4adbb769870bbfc43e42"
    },
    "feedback_event_type": "project_pack_compilation_feedback",
    "learning_candidate_reasons": [],
    "template_gaps": []
  },
  "identity": {
    "canonical_id": "project_528487c0c621cd07d9ed7826966a6d71",
    "canonical_name": "567-labs/instructor",
    "homepage_url": null,
    "license": "unknown",
    "repo_url": "https://github.com/567-labs/instructor",
    "slug": "instructor",
    "source_packet_id": "phit_f92be39d2ca741d4aead75b3be47c61d",
    "source_validation_id": "dval_8e661cfaee704158990079c366c444a8"
  },
  "merchandising": {
    "best_for": "需要安全审查与权限治理能力，并使用 chatgpt的用户",
    "github_forks": 1037,
    "github_stars": 12953,
    "one_liner_en": "structured outputs for llms",
    "one_liner_zh": "structured outputs for llms",
    "primary_category": {
      "category_id": "security-permissions",
      "confidence": "high",
      "name_en": "Security & Permissions",
      "name_zh": "安全审查与权限治理",
      "reason": "curated popular coverage category matched project identity"
    },
    "target_user": "使用 chatgpt 等宿主 AI 的用户",
    "title_en": "instructor",
    "title_zh": "instructor 能力包",
    "visible_tags": [
      {
        "label_en": "Knowledge Retrieval",
        "label_zh": "知识检索",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "product_domain-knowledge-retrieval",
        "type": "product_domain"
      },
      {
        "label_en": "Knowledge Base Q&A",
        "label_zh": "知识库问答",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "user_job-knowledge-base-q-a",
        "type": "user_job"
      },
      {
        "label_en": "Structured Data Extraction",
        "label_zh": "结构化数据提取",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "core_capability-structured-data-extraction",
        "type": "core_capability"
      },
      {
        "label_en": "Node-based Workflow",
        "label_zh": "节点式流程编排",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "workflow_pattern-node-based-workflow",
        "type": "workflow_pattern"
      },
      {
        "label_en": "Open Source Tool",
        "label_zh": "开源工具",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "selection_signal-open-source-tool",
        "type": "selection_signal"
      }
    ]
  },
  "packet_id": "phit_f92be39d2ca741d4aead75b3be47c61d",
  "page_model": {
    "artifacts": {
      "artifact_slug": "instructor",
      "files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json",
        "REPO_INSPECTION.md",
        "CAPABILITY_CONTRACT.json",
        "EVIDENCE_INDEX.json",
        "CLAIM_GRAPH.json"
      ],
      "required_files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json"
      ]
    },
    "detail": {
      "capability_source": "Project Hit Packet + DownstreamValidationResult",
      "commands": [
        {
          "command": "pip install instructor",
          "label": "Python / pip · 官方安装入口",
          "source": "https://github.com/567-labs/instructor#readme",
          "verified": true
        }
      ],
      "display_tags": [
        "知识检索",
        "知识库问答",
        "结构化数据提取",
        "节点式流程编排",
        "开源工具"
      ],
      "eyebrow": "安全审查与权限治理",
      "glance": [
        {
          "body": "判断自己是不是目标用户。",
          "label": "最适合谁",
          "value": "需要安全审查与权限治理能力，并使用 chatgpt的用户"
        },
        {
          "body": "先理解能力边界，再决定是否继续。",
          "label": "核心价值",
          "value": "structured outputs for llms"
        },
        {
          "body": "未完成验证前保持审慎。",
          "label": "继续前",
          "value": "publish to Doramagic.ai project surfaces"
        }
      ],
      "guardrail_source": "Boundary & Risk Card",
      "guardrails": [
        {
          "body": "Prompt Preview 只展示流程，不证明项目已安装或运行。",
          "label": "Check 1",
          "value": "不要把试用当真实运行"
        },
        {
          "body": "chatgpt",
          "label": "Check 2",
          "value": "确认宿主兼容"
        },
        {
          "body": "publish to Doramagic.ai project surfaces",
          "label": "Check 3",
          "value": "先隔离验证"
        }
      ],
      "mode": "skill, recipe, host_instruction, eval, preflight",
      "pitfall_log": {
        "items": [
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Documentation (at least Google-related) is an outdated mess.",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_b87b003416cd4308bc863f0cd66a68fd | https://github.com/567-labs/instructor/issues/2289 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：Documentation (at least Google-related) is an outdated mess.",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v1.13.0",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_f3c1e8416a744b51b5691317c10bc5bf | https://github.com/567-labs/instructor/releases/tag/v1.13.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.13.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.12.0",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_9b8236f58f8641c586777618a838409f | https://github.com/567-labs/instructor/releases/tag/v1.12.0 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.12.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.0",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_053ef3382ace48778d05ef006d87cead | https://github.com/567-labs/instructor/releases/tag/v1.14.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.14.0",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.3",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_d18c003929614c7097d16742ec94cc8c | https://github.com/567-labs/instructor/releases/tag/v1.14.3 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.14.3",
            "user_impact": "可能阻塞安装或首次运行。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.4",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_76987134f9a747d685958a5e98f3b51a | https://github.com/567-labs/instructor/releases/tag/v1.14.4 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.14.4",
            "user_impact": "可能阻塞安装或首次运行。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.15.0",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_430369db61e440e5a4b575e2b3618464 | https://github.com/567-labs/instructor/releases/tag/v1.15.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.15.0",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "README/documentation is current enough for a first validation pass.",
            "category": "能力坑",
            "evidence": [
              "capability.assumptions | github_repo:653589102 | https://github.com/567-labs/instructor | README/documentation is current enough for a first validation pass."
            ],
            "severity": "medium",
            "suggested_check": "将假设转成下游验证清单。",
            "title": "能力判断依赖假设",
            "user_impact": "假设不成立时，用户拿不到承诺的能力。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个运行相关的待验证问题：v1.14.2",
            "category": "运行坑",
            "evidence": [
              "community_evidence:github | cevd_fd561faf78f147518bcda7a0370a9a4f | https://github.com/567-labs/instructor/releases/tag/v1.14.2 | 来源讨论提到 node 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v1.14.2",
            "user_impact": "可能阻塞安装或首次运行。"
          },
          {
            "body": "未记录 last_activity_observed。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | last_activity_observed missing"
            ],
            "severity": "medium",
            "suggested_check": "补 GitHub 最近 commit、release、issue/PR 响应信号。",
            "title": "维护活跃度未知",
            "user_impact": "新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "downstream_validation.risk_items | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "进入安全/权限治理复核队列。",
            "title": "下游验证发现风险项",
            "user_impact": "下游已经要求复核，不能在页面中弱化。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "risks.scoring_risks | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "把风险写入边界卡，并确认是否需要人工复核。",
            "title": "存在评分风险",
            "user_impact": "风险会影响是否适合普通用户安装。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Catching IncompleteOutputException : not possible as presently documented / tested.",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_dc0f4256859740f8a4cacd1731514783 | https://github.com/567-labs/instructor/issues/2273 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：Catching IncompleteOutputException : not possible as presently documented / tested.",
            "user_impact": "可能影响授权、密钥配置或安全边界。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_b982358c78a346bfaa26b428e00968bb | https://github.com/567-labs/instructor/issues/2291 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bump lightllm upper bound for recent vulnerabililties",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_2ae9c53479204c778e56a8b4b3feb404 | https://github.com/567-labs/instructor/issues/2290 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：bump lightllm upper bound for recent vulnerabililties",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：logger.debug in response.py leaks api_key verbatim via new_kwargs",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_2076a35fb27a4c119141e9f57acdf9bc | https://github.com/567-labs/instructor/issues/2265 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：logger.debug in response.py leaks api_key verbatim via new_kwargs",
            "user_impact": "可能影响授权、密钥配置或安全边界。"
          }
        ],
        "source": "ProjectPitfallLog + ProjectHitPacket + validation + community signals",
        "summary": "发现 21 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：安装坑 - 来源证据：Documentation (at least Google-related) is an outdated mess.。",
        "title": "踩坑日志"
      },
      "snapshot": {
        "contributors": 250,
        "forks": 1037,
        "license": "unknown",
        "note": "站点快照，非实时质量证明；用于开工前背景判断。",
        "stars": 12953
      },
      "source_url": "https://github.com/567-labs/instructor",
      "steps": [
        {
          "body": "不安装项目，先体验能力节奏。",
          "code": "preview",
          "title": "先试 Prompt"
        },
        {
          "body": "理解输入、输出、失败模式和边界。",
          "code": "manual",
          "title": "读说明书"
        },
        {
          "body": "把上下文交给宿主 AI 继续工作。",
          "code": "context",
          "title": "带给 AI"
        },
        {
          "body": "进入主力环境前先完成安装入口与风险边界验证。",
          "code": "verify",
          "title": "沙箱验证"
        }
      ],
      "subtitle": "structured outputs for llms",
      "title": "instructor 能力包",
      "trial_prompt": "# instructor - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for 567-labs/instructor.\n\nProject:\n- Name: instructor\n- Repository: https://github.com/567-labs/instructor\n- Summary: structured outputs for llms\n- Host target: chatgpt\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: structured outputs for llms\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: structured outputs for llms\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. introduction: Introduction to Instructor. Produce one small intermediate artifact and wait for confirmation.\n2. getting-started: Getting Started with Instructor. Produce one small intermediate artifact and wait for confirmation.\n3. core-components: Core Components Architecture. Produce one small intermediate artifact and wait for confirmation.\n4. response-models: Response Models and Type Safety. Produce one small intermediate artifact and wait for confirmation.\n5. validation-retries: Validation and Retry Mechanisms. Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/567-labs/instructor\n- https://github.com/567-labs/instructor#readme\n- README.md\n- instructor/__init__.py\n- docs/getting-started.md\n- docs/learning/getting_started/first_extraction.md\n- examples/simple-extraction/user.py\n- instructor/core/client.py\n- instructor/core/hooks.py\n- instructor/core/retry.py\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n",
      "voices": [
        {
          "body": "来源平台：github。github/github_issue: Documentation (at least Google-related) is an outdated mess.（https://github.com/567-labs/instructor/issues/2289）；github/github_issue: Tool: NEXUS structured financial data（https://github.com/567-labs/instructor/issues/2302）；github/github_issue: Catching IncompleteOutputException : not possible as presently documente（https://github.com/567-labs/instructor/issues/2273）；github/github_issue: bump lightllm upper bound for recent vulnerabililties（https://github.com/567-labs/instructor/issues/2290）；github/github_issue: reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUse（https://github.com/567-labs/instructor/issues/2277）；github/github_issue: logger.debug in response.py leaks api_key verbatim via new_kwargs（https://github.com/567-labs/instructor/issues/2265）；github/github_issue: RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)（https://github.com/567-labs/instructor/issues/2291）；github/github_release: v1.15.1（https://github.com/567-labs/instructor/releases/tag/v1.15.1）；github/github_release: v1.15.0（https://github.com/567-labs/instructor/releases/tag/v1.15.0）；github/github_release: v1.14.5（https://github.com/567-labs/instructor/releases/tag/v1.14.5）；github/github_release: v1.14.4（https://github.com/567-labs/instructor/releases/tag/v1.14.4）；github/github_release: v1.14.3（https://github.com/567-labs/instructor/releases/tag/v1.14.3）。这些是项目级外部声音，不作为单独质量证明。",
          "items": [
            {
              "kind": "github_issue",
              "source": "github",
              "title": "Documentation (at least Google-related) is an outdated mess.",
              "url": "https://github.com/567-labs/instructor/issues/2289"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "Tool: NEXUS structured financial data",
              "url": "https://github.com/567-labs/instructor/issues/2302"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "Catching IncompleteOutputException : not possible as presently documente",
              "url": "https://github.com/567-labs/instructor/issues/2273"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bump lightllm upper bound for recent vulnerabililties",
              "url": "https://github.com/567-labs/instructor/issues/2290"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUse",
              "url": "https://github.com/567-labs/instructor/issues/2277"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "logger.debug in response.py leaks api_key verbatim via new_kwargs",
              "url": "https://github.com/567-labs/instructor/issues/2265"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)",
              "url": "https://github.com/567-labs/instructor/issues/2291"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v1.15.1",
              "url": "https://github.com/567-labs/instructor/releases/tag/v1.15.1"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v1.15.0",
              "url": "https://github.com/567-labs/instructor/releases/tag/v1.15.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v1.14.5",
              "url": "https://github.com/567-labs/instructor/releases/tag/v1.14.5"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v1.14.4",
              "url": "https://github.com/567-labs/instructor/releases/tag/v1.14.4"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v1.14.3",
              "url": "https://github.com/567-labs/instructor/releases/tag/v1.14.3"
            }
          ],
          "status": "已收录 12 条来源",
          "title": "社区讨论"
        }
      ]
    },
    "homepage_card": {
      "category": "安全审查与权限治理",
      "desc": "structured outputs for llms",
      "effort": "安装已验证",
      "forks": 1037,
      "icon": "shield",
      "name": "instructor 能力包",
      "risk": "可发布",
      "slug": "instructor",
      "stars": 12953,
      "tags": [
        "知识检索",
        "知识库问答",
        "结构化数据提取",
        "节点式流程编排",
        "开源工具"
      ],
      "thumb": "purple",
      "type": "Skill Pack"
    },
    "manual": {
      "markdown": "# https://github.com/567-labs/instructor 项目说明书\n\n生成时间：2026-05-16 03:25:27 UTC\n\n## 目录\n\n- [Introduction to Instructor](#introduction)\n- [Getting Started with Instructor](#getting-started)\n- [Installation and Setup](#installation)\n- [Project Structure](#project-structure)\n- [Core Components Architecture](#core-components)\n- [Response Models and Type Safety](#response-models)\n- [Validation and Retry Mechanisms](#validation-retries)\n- [Streaming and Partial Responses](#streaming)\n- [LLM Provider Support](#providers)\n- [Unified Provider Interface](#from-provider)\n\n<a id='introduction'></a>\n\n## Introduction to Instructor\n\n### 相关页面\n\n相关主题：[Getting Started with Instructor](#getting-started), [Installation and Setup](#installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [instructor/__init__.py](https://github.com/567-labs/instructor/blob/main/instructor/__init__.py) *(referenced but not directly included in context)*\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n</details>\n\n# Introduction to Instructor\n\nInstructor is an open-source Python library that simplifies structured output extraction from Large Language Models (LLMs). It provides a unified API across multiple LLM providers, enabling developers to define response models using Pydantic and automatically receive validated, typed outputs from AI responses.\n\n## Overview\n\nInstructor addresses a common challenge in LLM development: parsing and validating unstructured model outputs into structured data types. Traditional approaches require manual JSON parsing, custom validation logic, and provider-specific code. Instructor streamlines this by:\n\n- Integrating directly with existing LLM provider clients\n- Using Pydantic models for response schema definition\n- Automatically retrying failed validations\n- Supporting multiple providers through a unified interface\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Core Concepts\n\n### Response Model Pattern\n\nAt the heart of Instructor is the `response_model` parameter. Developers define a Pydantic `BaseModel` class that specifies the expected structure of the LLM response:\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Automatic Retries\n\nWhen validation fails (e.g., the LLM returns invalid data), Instructor automatically retries the request, passing the validation error back to the model for correction:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Supported Providers\n\nInstructor provides a unified API that works with multiple LLM providers. The `from_provider()` method creates a configured client for any supported provider.\n\n### Provider Support Matrix\n\n| Provider | Client Method | API Key Environment Variable |\n|----------|---------------|------------------------------|\n| OpenAI | `instructor.from_provider(\"openai/...\")` | `OPENAI_API_KEY` |\n| Anthropic | `instructor.from_provider(\"anthropic/...\")` | `ANTHROPIC_API_KEY` |\n| Google | `instructor.from_provider(\"google/...\")` | `GOOGLE_API_KEY` |\n| Ollama | `instructor.from_provider(\"ollama/...\")` | N/A (local) |\n| Groq | `instructor.from_provider(\"groq/...\")` | `GROQ_API_KEY` |\n\n### Supported Models by Provider\n\n**OpenAI Models:**\n- `openai/gpt-4o`\n- `openai/gpt-4o-mini`\n- `openai/gpt-4-turbo`\n\n**Anthropic Models:**\n- `anthropic/claude-3-5-sonnet-20241022`\n- `anthropic/claude-3-opus-20240229`\n- `anthropic/claude-3-haiku-20240307`\n\n**Google Models:**\n- `google/gemini-2.0-flash-001`\n- `google/gemini-pro`\n- `google/gemini-pro-vision`\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md), [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## Installation\n\n### Standard Installation\n\n```bash\npip install instructor\n```\n\n### Package Managers\n\n```bash\n# Using uv\nuv add instructor\n\n# Using poetry\npoetry add instructor\n```\n\n### API Key Configuration\n\nProviders can be configured using environment variables or passed directly:\n\n```python\n# From environment variables\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Direct API key\nclient = instructor.from_provider(\n    \"openai/gpt-4o\", \n    api_key=\"sk-...\"\n)\n\nclient = instructor.from_provider(\n    \"anthropic/claude-3-5-sonnet\",\n    api_key=\"sk-ant-...\"\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Advanced Features\n\n### Caching\n\nInstructor includes built-in caching mechanisms to reduce API calls and costs for repeated requests.\n\n**AutoCache (In-Memory LRU):**\n```python\nfrom instructor.cache import AutoCache\n\ncache = AutoCache(maxsize=100)\nclient = instructor.from_openai(OpenAI(), cache=cache)\n```\n\n**DiskCache (Persistent):**\n```python\nfrom instructor.cache import DiskCache\n\ncache = DiskCache(directory=\".instructor_cache\")\nclient = instructor.from_openai(OpenAI(), cache=cache)\n```\n\n**Cache TTL:**\n```python\nclient.create(\n    model=\"gpt-3.5-turbo\",\n    messages=messages,\n    response_model=User,\n    cache_ttl=3600,  # 1 hour\n)\n```\n\n**Performance Benefits:**\n- **156x faster** cache hits compared to API calls\n- **Identical results** from cache and API\n- **Persistent storage** across client instances\n- Cache invalidation based on prompts, models, schemas, and TTL\n\n资料来源：[examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n\n### Hooks System\n\nHooks allow developers to attach event handlers for monitoring and debugging LLM interactions.\n\n**Available Hook Events:**\n- Request details (model, prompt)\n- Input token count\n- Token usage statistics\n- Successful responses\n- Parse errors\n- Completion errors\n- Retry attempt notifications\n\n**Hook Types:**\n1. **On Request Hook**: Triggered before/after API requests\n2. **On Response Hook**: Triggered when responses are received\n3. **Parse Error Hook**: Handles JSON parsing failures\n4. **Completion Error Hook**: Handles API errors\n5. **Retry Hook**: Notifies on retry attempts\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### Batch Processing\n\nThe `BatchProcessor` provides a unified interface for creating batch jobs across providers.\n\n**Supported Operations:**\n```bash\n# Create batch from file\ninstructor batch create \\\n  --messages-file messages.jsonl \\\n  --model \"openai/gpt-4o-mini\" \\\n  --response-model \"examples.User\" \\\n  --output-file batch_requests.jsonl\n\n# Submit batch\ninstructor batch create-from-file \\\n  --file-path batch_requests.jsonl \\\n  --model \"openai/gpt-4o-mini\"\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Validation with LLM Validators\n\nBeyond standard Pydantic validators, Instructor supports `llm_validator` for complex validation scenarios:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Architecture\n\n### Provider Organization\n\nThe library organizes provider implementations in `instructor/providers/` with consistent patterns:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n**Provider Implementation Categories:**\n\n| Category | Providers |\n|----------|-----------|\n| Full Implementation (client.py + utils.py) | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai |\n| Client Only | genai, groq, vertexai |\n| Special (utils.py only) | openai |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Workflow Diagram\n\n```mermaid\ngraph TD\n    A[Define Pydantic Model] --> B[Create Instructor Client]\n    B --> C[Call create with response_model]\n    C --> D{Provider Selection}\n    D -->|OpenAI| E[OpenAI Handler]\n    D -->|Anthropic| F[Anthropic Handler]\n    D -->|Google| G[Google Handler]\n    E --> H[Parse Response]\n    F --> H\n    G --> H\n    H --> I{Validation Passed?}\n    I -->|Yes| J[Return Typed Object]\n    I -->|No| K[Retry with Error]\n    K --> C\n```\n\n## Example Applications\n\n### Citation Extraction\n\nInstructor powers applications that extract structured citations from documents:\n\n```bash\ncurl -X 'POST' \\\n  'https://jxnl--rag-citation-fastapi-app.modal.run/extract' \\\n  -H 'Authorization: Bearer <OPENAI_API_KEY>' \\\n  -d '{\n  \"context\": \"My name is Jason Liu...\",\n  \"query\": \"What did the author do in school?\"\n}'\n```\n\n**Response Format:**\n```json\n{\n  \"body\": \"In school, the author went to an arts high school.\",\n  \"spans\": [[91, 106]],\n  \"citation\": [\"arts highschool\"]\n}\n```\n\n资料来源：[examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n\n## Comparison: Without vs With Instructor\n\n| Aspect | Traditional Approach | With Instructor |\n|--------|----------------------|-----------------|\n| API Calls | Multiple calls for function definition | Single call |\n| Response Parsing | Manual JSON extraction | Automatic |\n| Validation | Custom error handling | Pydantic validation |\n| Retries | Manual implementation | Built-in automatic retries |\n| Provider Changes | Rewrite code | Same API across providers |\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Next Steps\n\n- Review the [official documentation](https://instructor-ai.github.io/instructor/) for detailed guides\n- Explore example implementations in the `examples/` directory\n- Contribute via GitHub issues and pull requests\n- Join the Instructor community for support and updates\n\n## License\n\nInstructor is released under the MIT License. See [LICENSE](https://github.com/567-labs/instructor/blob/main/LICENSE) for details.\n\n---\n\n<a id='getting-started'></a>\n\n## Getting Started with Instructor\n\n### 相关页面\n\n相关主题：[Installation and Setup](#installation), [Response Models and Type Safety](#response-models)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [scripts/README.md](https://github.com/567-labs/instructor/blob/main/scripts/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n</details>\n\n# Getting Started with Instructor\n\nInstructor is a Python library that simplifies structured data extraction from Large Language Model (LLM) responses. It integrates with multiple LLM providers and uses Pydantic for automatic validation, retry logic, and type safety. With Instructor, developers can define response models and receive fully validated, typed data directly from LLM outputs.\n\n资料来源：[README.md:1-50]()\n\n## Installation\n\nInstall Instructor using pip or your preferred package manager:\n\n```bash\npip install instructor\n```\n\nOr with alternative package managers:\n\n```bash\nuv add instructor\npoetry add instructor\n```\n\n资料来源：[README.md:51-60]()\n\n## Quick Start\n\nThe simplest way to use Instructor is with the `from_provider()` factory function:\n\n```python\nfrom pydantic import BaseModel\nimport instructor\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\n\n\nclass Product(BaseModel):\n    name: str\n    price: float\n    in_stock: bool\n\n\nproduct = client.chat.completions.create(\n    response_model=Product,\n    messages=[{\"role\": \"user\", \"content\": \"iPhone 15 Pro, $999, available now\"}],\n)\n\nprint(product)\n# Product(name='iPhone 15 Pro', price=999.0, in_stock=True)\n```\n\n资料来源：[README.md:125-150]()\n\n## Supported Providers\n\nInstructor works with multiple LLM providers using a unified API. The provider is automatically detected from the model identifier.\n\n### Provider Configuration Table\n\n| Provider | Model Identifier | API Key Parameter |\n|----------|------------------|-------------------|\n| OpenAI | `openai/gpt-4o-mini`, `openai/gpt-4o` | `api_key` |\n| Anthropic | `anthropic/claude-3-5-sonnet` | `api_key` |\n| Google | `google/gemini-pro` | `api_key` |\n| Ollama (local) | `ollama/llama3.2` | Local only |\n| Groq | `groq/llama-3.1-8b-instant` | `api_key` |\n\n### Usage Examples by Provider\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n\n# With explicit API keys\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n```\n\n资料来源：[README.md:61-90]()\n\n## Response Models\n\nResponse models define the expected output structure using Pydantic's `BaseModel`. Instructor automatically parses and validates LLM responses against these models.\n\n### Basic Model Definition\n\n```python\nfrom pydantic import BaseModel\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n### Without Instructor vs With Instructor\n\n```mermaid\ngraph TD\n    A[User Request] --> B[LLM API Call]\n    B --> C{Using Instructor?}\n    C -->|No| D[Raw JSON Response]\n    D --> E[Manual Parsing]\n    E --> F[Manual Validation]\n    F --> G[Handle Errors]\n    C -->|Yes| H[Response Model Defined]\n    H --> I[Automatic Parsing]\n    I --> J[Automatic Validation]\n    J --> K[Validated Output]\n```\n\n资料来源：[README.md:1-40]()\n\n## Validation\n\nInstructor provides automatic retry logic when validation fails. Define custom validators using Pydantic's `@field_validator` decorator.\n\n### Automatic Retries\n\n```python\nfrom pydantic import BaseModel, field_validator\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md:35-50]()\n\n### Custom LLM Validation\n\nUse `llm_validator` for content-based validation:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md:1-50]()\n\n## Hooks System\n\nHooks allow you to intercept and process requests and responses. The hooks system provides visibility into API calls.\n\n### Available Hook Events\n\n1. **Request Hook**: Triggered before sending a request to the LLM\n2. **Parse Error Hook**: Triggered when response parsing fails\n3. **Multiple Hooks**: Shows how to attach multiple handlers to the same event\n\n### Hook Usage Example\n\n```python\n# Hooks provide detailed information about each request:\n# - Request details (model, prompt)\n# - Approximate input token count\n# - Token usage statistics\n# - Successful responses\n# - Parse errors\n# - Completion errors\n# - Retry attempt notifications\n```\n\n资料来源：[examples/hooks/README.md:1-40]()\n\n## Advanced Features\n\n### Citation with Extraction\n\nExtract structured data with precise citations from source text:\n\n```python\n# FastAPI endpoint example\nresponse = client.chat.completions.create(\n    response_model=Facts,\n    messages=[...],\n)\n# Returns extracted facts with exact span positions and citations\n```\n\n资料来源：[examples/citation_with_extraction/README.md:1-80]()\n\n### Batch Processing\n\nProcess multiple requests efficiently using batch APIs:\n\n```bash\n# Test OpenAI\npython run_batch_test.py create --model \"openai/gpt-4o-mini\"\n\n# Test Anthropic\npython run_batch_test.py create --model \"anthropic/claude-3-5-sonnet-20241022\"\n```\n\n**Supported Batch Models Table**\n\n| Provider | Models |\n|----------|--------|\n| OpenAI | `gpt-4o-mini`, `gpt-4o`, `gpt-4-turbo` |\n| Anthropic | `claude-3-5-sonnet-20241022`, `claude-3-opus-20240229`, `claude-3-haiku-20240307` |\n| Google | `gemini-2.0-flash-001`, `gemini-pro`, `gemini-pro-vision` |\n\n资料来源：[examples/batch_api/README.md:1-70]()\n\n### Fine-Tuning and Distillation\n\nGenerate fine-tuning datasets from Instructor outputs:\n\n```bash\n# Run the script to generate training data\npython three_digit_mul.py\n\n# Create fine-tuning job\ninstructor jobs create-from-file math_finetunes.jsonl\n\n# With validation data\ninstructor jobs create-from-file math_finetunes.jsonl --n-epochs 4 --validation-file math_finetunes_val.jsonl\n```\n\n资料来源：[examples/distilations/readme.md:1-60]()\n\n## Provider Architecture\n\nEach provider is organized in its own subdirectory under `providers/`:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n### Provider Implementation Patterns\n\n| Pattern | Providers |\n|---------|-----------|\n| Both `client.py` and `utils.py` | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai |\n| Only `client.py` | genai, groq, vertexai |\n| Only `utils.py` (core) | OpenAI |\n\n资料来源：[instructor/providers/README.md:1-40]()\n\n## Utility Scripts\n\nThe repository includes maintenance scripts in the `scripts/` directory:\n\n| Script | Purpose |\n|--------|---------|\n| `make_clean.py` | Cleans markdown files, removes special whitespace characters |\n| `check_blog_excerpts.py` | Validates blog posts contain `<!-- more -->` tags |\n| `make_sitemap.py` | Generates sitemap with AI-powered content analysis |\n| `fix_api_calls.py` | Standardizes API call patterns |\n| `audit_patterns.py` | Audits documentation for outdated patterns |\n\n### Script Usage\n\n```bash\n# Clean markdown files\npython scripts/make_clean.py --dry-run\n\n# Check blog excerpts\npython scripts/check_blog_excerpts.py\n\n# Generate sitemap\npython scripts/make_sitemap.py\n\n# Audit documentation\npython scripts/audit_patterns.py --summary\n```\n\n资料来源：[scripts/README.md:1-100]()\n\n## Next Steps\n\n- Explore the [examples directory](https://github.com/567-labs/instructor/tree/main/examples) for complete working examples\n- Review the [validators documentation](examples/validators/readme.md) for advanced validation patterns\n- Learn about [hooks](examples/hooks/README.md) for request introspection\n- Set up [batch processing](examples/batch_api/README.md) for large-scale extractions\n- Consider [fine-tuning](examples/distilations/readme.md) for domain-specific tasks\n\n## Statistics and Community\n\nInstructor is trusted by over 100,000 developers and used in production by teams at OpenAI, Google, Microsoft, and AWS.\n\n| Metric | Value |\n|--------|-------|\n| Monthly Downloads | 3M+ |\n| GitHub Stars | 10K+ |\n| Contributors | 1000+ |\n\n资料来源：[README.md:95-110]()\n\n---\n\n<a id='installation'></a>\n\n## Installation and Setup\n\n### 相关页面\n\n相关主题：[Getting Started with Instructor](#getting-started), [LLM Provider Support](#providers)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n- [examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n</details>\n\n# Installation and Setup\n\n## Overview\n\nInstructor is a Python library that enables structured outputs from Large Language Models (LLMs) using type validation through Pydantic. It provides a unified API across multiple LLM providers, allowing developers to define response models and receive type-safe, validated responses automatically.\n\n资料来源：[README.md:1-50]()\n\n## System Requirements\n\n| Requirement | Specification |\n|------------|---------------|\n| Python Version | 3.9 or higher |\n| Package Manager | pip, uv, or poetry |\n| Optional Dependencies | OpenAI, Anthropic, Google SDKs based on provider selection |\n\n资料来源：[examples/distilations/readme.md:10-12]()\n\n## Installation Methods\n\n### Using pip\n\nThe simplest installation method uses pip:\n\n```bash\npip install instructor\n```\n\n资料来源：[README.md:60]()\n\n### Using uv\n\nFor projects using uv as the package manager:\n\n```bash\nuv add instructor\n```\n\n资料来源：[README.md:64]()\n\n### Using poetry\n\nFor projects using Poetry for dependency management:\n\n```bash\npoetry add instructor\n```\n\n资料来源：[README.md:65]()\n\n## Provider Setup\n\nInstructor supports multiple LLM providers with a unified interface. The following diagram illustrates the provider architecture:\n\n```mermaid\ngraph TD\n    A[Application Code] --> B[Instructor Client]\n    B --> C{Provider Type}\n    C -->|OpenAI| D[OpenAI Provider]\n    C -->|Anthropic| E[Anthropic Provider]\n    C -->|Google| F[Gemini Provider]\n    C -->|Ollama| G[Ollama Provider]\n    C -->|Groq| H[Groq Provider]\n    C -->|VertexAI| I[VertexAI Provider]\n    D --> J[Provider API]\n    E --> J\n    F --> J\n    G --> J\n    H --> J\n    I --> J\n```\n\n资料来源：[README.md:70-90]()\n\n### Basic Provider Initialization\n\nInitialize clients using the `from_provider()` factory function:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md:70-85]()\n\n### API Key Configuration\n\nAPI keys can be configured in two ways:\n\n| Method | Configuration |\n|--------|---------------|\n| Environment Variable | Set provider-specific env var (e.g., `OPENAI_API_KEY`) |\n| Direct Parameter | Pass `api_key` parameter to `from_provider()` |\n\n#### Direct API Key Configuration\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n\n# Groq\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\n资料来源：[README.md:85-92]()\n\n## Basic Usage Pattern\n\nThe fundamental usage pattern involves:\n\n1. Creating an instructor client\n2. Defining a Pydantic response model\n3. Calling the client with the response model\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md:45-55]()\n\n## Provider-Specific Initialization\n\nSome providers may require additional setup:\n\n### OpenAI Provider\n\nThe OpenAI provider is the reference implementation and uses `from_openai()` or `from_provider()`:\n\n```python\nimport instructor\nimport openai\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\n```\n\n资料来源：[README.md:70-72]()\n\n### Anthropic Provider\n\nRequires the `ANTHROPIC_API_KEY` environment variable:\n\n```bash\nexport ANTHROPIC_API_KEY=\"your-anthropic-api-key\"\n```\n\n资料来源：[examples/batch_api/README.md:45-50]()\n\n### Google Provider\n\nFor Gemini models, ensure the Google SDK is installed and `GOOGLE_API_KEY` is set:\n\n```bash\npip install google-generativeai\n```\n\n资料来源：[examples/batch_api/README.md:55-60]()\n\n## Optional Dependencies\n\nDepending on your use case, you may need additional dependencies:\n\n### For Caching Features\n\n```python\nfrom instructor.cache import AutoCache, DiskCache\n```\n\n资料来源：[examples/caching_prototype/README.md:12-15]()\n\n### For Validation\n\n```python\nfrom instructor import llm_validator, patch\n```\n\n资料来源：[examples/validators/readme.md:15-17]()\n\n### For Sitemap Generation (Documentation Scripts)\n\n```bash\nuv add openai typer rich tenacity pyyaml\n```\n\n资料来源：[scripts/README.md:85-87]()\n\n## Supported Models by Provider\n\n| Provider | Models |\n|----------|--------|\n| OpenAI | gpt-4o-mini, gpt-4o, gpt-4-turbo |\n| Anthropic | claude-3-5-sonnet-20241022, claude-3-opus-20240229, claude-3-haiku-20240307 |\n| Google | gemini-2.0-flash-001, gemini-pro, gemini-pro-vision |\n| Ollama | llama3.2, and other local models |\n\n资料来源：[examples/batch_api/README.md:25-35]()\n\n## Verification Installation\n\nTo verify your installation, create a simple test:\n\n```python\nimport instructor\nfrom pydantic import BaseModel\n\nclass TestModel(BaseModel):\n    result: str\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\nresult = client.chat.completions.create(\n    model=\"gpt-4o-mini\",\n    response_model=TestModel,\n    messages=[{\"role\": \"user\", \"content\": \"Say 'Hello, World!'\"}],\n)\nprint(result.result)  # Should print: Hello, World!\n```\n\n## Common Setup Issues\n\n| Issue | Solution |\n|-------|----------|\n| API key not found | Set the appropriate environment variable or pass `api_key` parameter |\n| Invalid model format | Use format `provider/model-name`, e.g., `openai/gpt-4o-mini` |\n| Unsupported provider | Use `openai`, `anthropic`, `google`, `ollama`, or `groq` |\n\n资料来源：[examples/batch_api/README.md:65-75]()\n\n## Next Steps\n\nAfter installation, consider exploring:\n\n- **Response Models**: Define Pydantic models for structured outputs\n- **Validation**: Add custom validators to response models\n- **Retries**: Instructor automatically retries failed validations\n- **Hooks**: Add logging and monitoring to requests\n\n资料来源：[README.md:95-115]()\n\n## Provider Architecture Details\n\nThe providers directory follows a consistent structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\nNot all providers require both files. Simpler providers like `genai`, `groq`, and `vertexai` use only `client.py`, while more complex ones like `anthropic`, `bedrock`, and `gemini` include both files.\n\n资料来源：[providers/README.md:1-25]()\n\n## Adding New Providers\n\nTo add support for a new LLM provider:\n\n1. Create a new subdirectory under `providers/`\n2. Add an `__init__.py` file\n3. Implement the `from_<provider>()` factory function\n4. Add provider-specific utilities as needed\n\n资料来源：[providers/README.md:27-32]()\n\n---\n\n<a id='project-structure'></a>\n\n## Project Structure\n\n### 相关页面\n\n相关主题：[Core Components Architecture](#core-components), [LLM Provider Support](#providers)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# Project Structure\n\n## Overview\n\nInstructor is a Python library that enables structured outputs from Large Language Models (LLMs) using Pydantic models for type validation. The project is organized into a modular architecture that separates core functionality, provider implementations, and example applications.\n\nThe primary goal of Instructor's project structure is to provide a unified API that works across multiple LLM providers while maintaining clean separation of concerns between client logic, provider-specific implementations, and response processing.\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    A[User Code] --> B[Core Client API]\n    B --> C[Provider Detection]\n    C --> D{Provider Type}\n    D -->|OpenAI| E[OpenAI Utils]\n    D -->|Anthropic| F[Anthropic Client]\n    D -->|Google| G[Gemini Utils]\n    D -->|Other| H[Provider-specific]\n    E --> I[Response Processing]\n    F --> I\n    G --> I\n    H --> I\n    I --> J[Pydantic Validation]\n    J --> K[Typed Response Model]\n```\n\n资料来源：[instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n\n## Directory Structure\n\n```\ninstructor/\n├── core/                    # Core client and base functionality\n│   ├── client.py           # Main client implementation\n│   └── ...\n├── providers/              # Provider-specific implementations\n│   ├── anthropic/          # Anthropic Claude integration\n│   ├── bedrock/            # AWS Bedrock integration\n│   ├── cerebras/           # Cerebras integration\n│   ├── cohere/             # Cohere integration\n│   ├── fireworks/          # Fireworks AI integration\n│   ├── gemini/             # Google Gemini integration\n│   ├── genai/              # Google Generative AI\n│   ├── groq/               # Groq integration\n│   ├── mistral/            # Mistral AI integration\n│   ├── perplexity/         # Perplexity AI integration\n│   ├── vertexai/           # Google Vertex AI integration\n│   ├── writer/             # Writer AI integration\n│   ├── xai/                 # xAI integration\n│   └── README.md           # Provider documentation\n├── processing/             # Response processing and validation\n│   ├── schema.py           # Schema handling\n│   └── ...\n├── cli/                    # Command-line interface\n│   └── ...\n└── ...\n\nexamples/\n├── batch_api/              # Batch processing examples\n├── citation_with_extraction/ # Extraction examples\n├── distilations/           # Fine-tuning examples\n├── hooks/                  # Hook system examples\n└── validators/             # Validation examples\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Core Components\n\n### Core Client Module\n\nThe core client module (`instructor/core/client.py`) provides the unified API for all LLM providers. It handles:\n\n| Component | Purpose |\n|-----------|---------|\n| `from_provider()` | Factory function to create provider-specific clients |\n| `client.create()` | Unified method for structured completions |\n| `client.create_partial()` | Streaming partial responses |\n| `client.create_iterable()` | Iterable response handling |\n| `client.create_with_completion()` | Responses with completion metadata |\n\n资料来源：[instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n\n### Basic Usage Pattern\n\n```python\n# Create client from any supported provider\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Use unified API for structured outputs\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Provider System\n\n### Provider Organization\n\nEach provider follows a consistent directory structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py    # Module exports\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Categories\n\n| Category | Providers | Files |\n|----------|-----------|-------|\n| Full Implementation | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai | `client.py` + `utils.py` |\n| Simplified | genai, groq, vertexai | `client.py` only |\n| Reference | openai | `utils.py` only (core handles `from_openai()`) |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Supported Providers\n\n```mermaid\ngraph LR\n    A[Instructor] --> B[OpenAI]\n    A --> C[Anthropic]\n    A --> D[Google]\n    A --> E[Groq]\n    A --> F[Vertex AI]\n    A --> G[Mistral]\n    A --> H[ Cohere]\n    A --> I[Fireworks]\n    A --> J[Cerebras]\n    A --> K[Perplexity]\n    A --> L[Writer]\n    A --> M[xAI]\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Processing Module\n\nThe processing module (`instructor/processing/`) handles response parsing and validation:\n\n| Component | Purpose |\n|-----------|---------|\n| Schema Handler | Transforms Pydantic models into LLM-compatible schemas |\n| Response Parser | Extracts structured data from LLM responses |\n| Validation Engine | Validates responses against Pydantic models |\n\n资料来源：[instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n\n## Example Applications\n\nThe `examples/` directory contains functional demonstrations:\n\n| Example | Purpose |\n|---------|---------|\n| `batch_api/` | Batch processing with multiple providers |\n| `citation_with_extraction/` | Fact extraction with citations |\n| `distilations/` | Model fine-tuning with Instructor |\n| `hooks/` | Event hook system for monitoring |\n| `validators/` | Custom validation with `llm_validator` |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Batch Processing Architecture\n\n```mermaid\ngraph TD\n    A[User Messages] --> B[BatchProcessor]\n    B --> C[Provider Detection]\n    C --> D{Provider}\n    D -->|OpenAI| E[batch.jsonl]\n    D -->|Anthropic| F[beta.messages.batches]\n    D -->|Google| G[GCS Simulation]\n    E --> H[Batch Submission]\n    F --> H\n    G --> H\n    H --> I[Batch ID Storage]\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Hooks System\n\nThe hooks system enables monitoring and logging of API operations:\n\n```python\n# Hook event types\n- on_request: Triggered before API call\n- on_response: Triggered after successful response\n- on_retry: Triggered during retry attempts\n- on_error: Triggered on validation/parse errors\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### Validation Examples\n\nCustom validation is achieved using Pydantic validators:\n\n```python\nfrom instructor import llm_validator, patch\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## CLI Tools\n\nThe project includes a command-line interface for common operations:\n\n```bash\n# Batch processing\ninstructor batch create --messages-file messages.jsonl --model \"openai/gpt-4o-mini\"\n\n# Fine-tuning job creation\ninstructor jobs create-from-file math_finetunes.jsonl\n```\n\n资料来源：[examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n\n## Installation and Dependencies\n\nThe project supports multiple package managers:\n\n```bash\n# pip\npip install instructor\n\n# uv\nuv add instructor\n\n# poetry\npoetry add instructor\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Scripts and Maintenance\n\nThe `scripts/` directory contains maintenance utilities:\n\n| Script | Purpose |\n|--------|---------|\n| `make_clean.py` | Clean markdown whitespace and dashes |\n| `make_sitemap.py` | Generate documentation sitemap |\n| `fix_api_calls.py` | Standardize API call patterns |\n| `fix_old_patterns.py` | Update deprecated patterns |\n| `audit_patterns.py` | Find outdated patterns in docs |\n\n资料来源：[scripts/README.md](https://github.com/567-labs/instructor/blob/main/scripts/README.md)\n\n## Key Design Patterns\n\n### Unified API Pattern\n\nInstructor provides a consistent interface across all providers:\n\n```python\n# Same code works for any provider\nclient = instructor.from_provider(\"provider/model-name\")\nresult = client.chat.completions.create(\n    response_model=YourModel,\n    messages=[...]\n)\n```\n\n### Factory Pattern\n\nThe `from_provider()` factory function creates appropriate clients based on the provider string:\n\n```python\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\nclient = instructor.from_provider(\"google/gemini-pro\")\n```\n\n### Validation Pipeline\n\n```mermaid\ngraph LR\n    A[LLM Response] --> B[Parse Tool Call]\n    B --> C[Extract Arguments]\n    C --> D[JSON Deserialization]\n    D --> E[Pydantic Validation]\n    E -->|Success| F[Typed Response]\n    E -->|Failure| G[Retry with Error]\n    G --> A\n```\n\n## Version Compatibility Notes\n\n- OpenAI uses a specialized `utils.py` without a `client.py` because `from_openai()` is defined in the core client\n- This is because OpenAI serves as the reference implementation for the library\n- OpenAI utilities are still required by core processing logic for standard handling\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n---\n\n<a id='core-components'></a>\n\n## Core Components Architecture\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>Relevant Source Files</summary>\n\nThe following source files are referenced for this page:\n\n- [instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n- [instructor/core/hooks.py](https://github.com/567-labs/instructor/blob/main/instructor/core/hooks.py)\n- [instructor/core/retry.py](https://github.com/567-labs/instructor/blob/main/instructor/core/retry.py)\n- [instructor/process_response.py](https://github.com/567-labs/instructor/blob/main/instructor/process_response.py)\n</details>\n\n# Core Components Architecture\n\n## Overview\n\nThe Instructor library is built on a modular architecture that enables structured LLM outputs with automatic validation and retry capabilities. The core components work together to provide a unified API across multiple LLM providers while maintaining extensibility through hooks and a robust retry mechanism.\n\n```mermaid\ngraph TD\n    A[User Code] --> B[Instructor Client]\n    B --> C[Provider Adapter]\n    C --> D[LLM API]\n    D --> E[Response]\n    E --> F[Response Processor]\n    F --> G[Validation]\n    G -->|Success| H[Typed Response]\n    G -->|Failure| I[Retry Logic]\n    I -->|Retry| D\n    I -->|Max Retries| J[Error]\n    F --> K[Hooks System]\n    K -->|On Response| B\n    K -->|On Validation Error| B\n```\n\n## Architecture Components\n\n### 1. Client Module (`instructor/core/client.py`)\n\nThe client module serves as the primary entry point for the Instructor library. It provides factory functions for creating provider-specific clients and implements the unified API interface.\n\n#### Key Responsibilities\n\n| Responsibility | Description |\n|---------------|-------------|\n| Client Factory | Creates provider-specific clients via `from_provider()` |\n| API Unification | Provides consistent interface across all LLM providers |\n| Method Dispatch | Routes `create()`, `create_partial()`, `create_iterable()` calls |\n| Response Model Handling | Passes response models to the processing pipeline |\n\n#### Supported Providers\n\nThe client architecture supports multiple providers through a consistent interface:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n\n# Groq\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\")\n```\n\n#### Core Client Interface\n\nThe unified client provides these primary methods:\n\n| Method | Purpose |\n|--------|---------|\n| `create()` | Standard response generation with full validation |\n| `create_partial()` | Streaming partial responses for progressive validation |\n| `create_iterable()` | Iterative generation for list/collection outputs |\n| `create_with_completion()` | Returns both the parsed response and completion details |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### 2. Hooks System (`instructor/core/hooks.py`)\n\nThe hooks system provides event-driven extensibility, allowing developers to intercept and respond to various stages of the LLM interaction lifecycle.\n\n#### Available Hook Events\n\n| Hook Event | Trigger | Common Use Cases |\n|------------|---------|------------------|\n| `on_request` | Before sending request to LLM | Logging, token counting |\n| `on_response` | After receiving response | Metrics collection |\n| `on_retry` | Before retry attempt | Retry count logging |\n| `on_validation_error` | When validation fails | Custom error handling |\n| `on_parse_error` | When response parsing fails | Debugging, fallback logic |\n\n#### Hook Handler Structure\n\n```mermaid\ngraph LR\n    A[LLM Request] --> B[on_request Hooks]\n    B --> C[API Call]\n    C --> D[on_response Hooks]\n    D --> E{Validation}\n    E -->|Pass| F[on_success Hooks]\n    E -->|Fail| G[on_validation_error Hooks]\n    F --> H[Return Response]\n    G --> I[Retry Logic]\n    I --> J[on_retry Hooks]\n```\n\n#### Hook Implementation Pattern\n\n```python\nfrom instructor.hooks import Hooks, HookEvent\n\nclass LoggingHooks(Hooks):\n    def on_request(self, request, **kwargs):\n        print(f\"🔍 Request: {request}\")\n        \n    def on_response(self, response, **kwargs):\n        print(f\"✅ Response received\")\n\n# Attach hooks to client\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient.attach_hooks(LoggingHooks())\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### 3. Retry Mechanism (`instructor/core/retry.py`)\n\nThe retry module handles automatic retries when validation fails, implementing exponential backoff and maximum retry limits.\n\n#### Retry Configuration\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `max_retries` | 3 | Maximum number of retry attempts |\n| `initial_delay` | 1.0 | Initial delay between retries (seconds) |\n| `backoff_factor` | 2.0 | Multiplier for delay on each retry |\n| `max_delay` | 60.0 | Maximum delay between retries (seconds) |\n\n#### Retry Flow\n\n```mermaid\ngraph TD\n    A[Initial Call] --> B{Validation Pass?}\n    B -->|Yes| C[Return Response]\n    B -->|No| D{Retry Count < Max?}\n    D -->|Yes| E[Apply Backoff]\n    E --> F[Log Error]\n    F --> A\n    D -->|No| G[Raise Exception]\n```\n\n#### Custom Retry with Field Validators\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### 4. Response Processing (`instructor/process_response.py`)\n\nThe response processing module handles parsing LLM outputs into structured Pydantic models, including text parsing, JSON extraction, and model validation.\n\n#### Processing Pipeline\n\n| Stage | Component | Function |\n|-------|-----------|----------|\n| 1 | Raw Response | Receive response from LLM provider |\n| 2 | Content Extraction | Extract text content from provider-specific format |\n| 3 | JSON Parsing | Parse JSON from text content |\n| 4 | Model Instantiation | Create Pydantic model instance |\n| 5 | Validation | Run Pydantic validators |\n| 6 | Error Handling | Trigger retries or raise exceptions |\n\n#### Validation Error Handling\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BaseModel, BeforeValidator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n\ntry:\n    qa: QuestionAnswerNoEvil = client.chat.completions.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[...],\n    )\nexcept Exception as e:\n    print(e)  # Handles validation errors\n```\n\n#### LLM-Based Validation\n\nThe response processor supports `llm_validator` for semantic validation beyond Pydantic type checking:\n\n```python\nfrom instructor import llm_validator\n\nclass OutputModel(BaseModel):\n    reasoning: Annotated[str, BeforeValidator(llm_validator(\"be logical\"))]\n    answer: Annotated[str, BeforeValidator(llm_validator(\"be concise\"))]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Provider Architecture\n\n### Provider Organization\n\nThe `providers/` directory follows a consistent structure across all supported providers:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n#### Provider Categories\n\n| Category | Providers | Characteristics |\n|----------|-----------|-----------------|\n| Full Implementation | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai | Custom client.py + utils.py |\n| Simplified | genai, groq, vertexai | client.py only |\n| Reference | openai | utils.py only (core implementation) |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Detection\n\nThe unified client automatically detects the provider from the model string format:\n\n```python\n# Format: provider/model-name\nclient = instructor.from_provider(\"openai/gpt-4o\")\n#   - Provider: openai\n#   - Model: gpt-4o\n\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n#   - Provider: anthropic\n#   - Model: claude-3-5-sonnet\n```\n\n## Data Flow Diagram\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant Client\n    participant Provider\n    participant Processor\n    participant Validator\n    participant Hooks\n\n    User->>Client: create(response_model, messages)\n    Client->>Hooks: on_request\n    Client->>Provider: API Call\n    Provider->>Client: Raw Response\n    Client->>Processor: Parse Response\n    Processor->>Validator: Validate Model\n    Validator-->>Processor: Valid/Invalid\n    alt Valid\n        Processor->>Client: Parsed Response\n        Client->>Hooks: on_response\n        Client-->>User: Typed Response\n    else Invalid\n        Processor->>Hooks: on_validation_error\n        Client->>Hooks: on_retry\n        Client->>Provider: Retry API Call\n        Note over Client: Loop until max_retries\n    end\n```\n\n## Configuration Options\n\n### Client Configuration\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `response_model` | Pydantic Model | Required | The expected response structure |\n| `max_retries` | int | 3 | Maximum validation retry attempts |\n| `validation_context` | dict | None | Additional context for validators |\n| `max_tokens` | int | Provider default | Maximum output tokens |\n| `temperature` | float | Provider default | Sampling temperature |\n\n### Provider-Specific Configuration\n\n```python\n# With API keys directly\nclient = instructor.from_provider(\n    \"openai/gpt-4o\", \n    api_key=\"sk-...\"\n)\n\nclient = instructor.from_provider(\n    \"anthropic/claude-3-5-sonnet\", \n    api_key=\"sk-ant-...\"\n)\n\n# With custom settings\nclient = instructor.from_provider(\n    \"openai/gpt-4o\",\n    api_key=\"sk-...\",\n    max_retries=5,\n    timeout=30.0\n)\n```\n\n## Key Design Patterns\n\n### 1. Factory Pattern\n\nThe `from_provider()` factory method creates appropriate client instances based on the provider string:\n\n```python\ndef from_provider(provider: str, **kwargs) -> Instructor:\n    \"\"\"Factory function to create provider-specific client.\"\"\"\n```\n\n### 2. Adapter Pattern\n\nEach provider implements a consistent interface while handling provider-specific nuances:\n\n```mermaid\ngraph TD\n    A[Instructor API] --> B[Provider Adapter]\n    B --> C[OpenAI Adapter]\n    B --> D[Anthropic Adapter]\n    B --> E[Google Adapter]\n    B --> F[Other Providers]\n```\n\n### 3. Decorator Pattern\n\nHooks provide a way to extend functionality without modifying core classes:\n\n```python\n@hooks.on_response\ndef log_response(response):\n    # Logging functionality\n    pass\n```\n\n## Error Handling\n\n### Error Types\n\n| Error Type | Cause | Recovery Action |\n|------------|-------|------------------|\n| `ValidationError` | Pydantic validation fails | Automatic retry with error message |\n| `ParseError` | JSON parsing fails | Automatic retry |\n| `MaxRetriesExceeded` | All retries exhausted | Raise exception to user |\n| `APIError` | Provider API failure | Retry with backoff |\n\n### Exception Flow\n\n```mermaid\ngraph TD\n    A[API Call] --> B{Success?}\n    B -->|No| C[API Error]\n    C --> D{Retry < Max?}\n    D -->|Yes| E[Backoff]\n    E --> A\n    D -->|No| F[Raise APIError]\n    B -->|Yes| G[Parse Response]\n    G --> H{Parse Success?}\n    H -->|No| I[Parse Error]\n    I --> D\n    H -->|Yes| J[Validate Model]\n    J --> K{Valid?}\n    K -->|Yes| L[Return Result]\n    K -->|No| M[Validation Error]\n    M --> D\n```\n\n## Summary\n\nThe Core Components Architecture of Instructor provides:\n\n1. **Unified Client Interface** - Single API across all LLM providers\n2. **Automatic Validation** - Pydantic-based response validation\n3. **Smart Retries** - Automatic retry with exponential backoff\n4. **Extensible Hooks** - Event-driven customization\n5. **Provider Abstraction** - Consistent patterns across providers\n\nThis architecture enables developers to focus on application logic while Instructor handles the complexities of structured LLM outputs, validation, and error recovery.\n\n---\n\n<a id='response-models'></a>\n\n## Response Models and Type Safety\n\n### 相关页面\n\n相关主题：[Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [docs/concepts/models.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/models.md)\n- [docs/concepts/fields.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/fields.md)\n- [docs/learning/getting_started/response_models.md](https://github.com/567-labs/instructor/blob/main/docs/learning/getting_started/response_models.md)\n- [instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n</details>\n\n# Response Models and Type Safety\n\n## Overview\n\nInstructor provides robust **Response Models** and **Type Safety** mechanisms that enable structured, validated outputs from Large Language Models. By leveraging Pydantic's validation system, Instructor ensures that LLM responses conform to expected schemas while automatically retrying failed validations.\n\n## What are Response Models?\n\nResponse Models are Pydantic `BaseModel` classes that define the expected structure and types of LLM outputs. They serve as a contract between your application and the LLM, ensuring type-safe, validated responses.\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Core Architecture\n\n```mermaid\ngraph TD\n    A[LLM API Call] --> B[Instructor Client]\n    B --> C[Response Model Definition]\n    C --> D[Pydantic Schema Validation]\n    D --> E{Validation Pass?}\n    E -->|Yes| F[Return Validated Object]\n    E -->|No| G[Extract Error Message]\n    G --> H[Retry with Error Context]\n    H --> B\n```\n\n## Using Response Models\n\n### Basic Usage\n\n```python\nfrom instructor import from_provider\nfrom pydantic import BaseModel\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"Extract: Jason is 28 years old\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Nested Response Models\n\nResponse Models support nested structures for complex data:\n\n```python\nclass Address(BaseModel):\n    street: str\n    city: str\n    country: str\n\nclass UserProfile(BaseModel):\n    name: str\n    age: int\n    address: Address\n```\n\n## Field Validators\n\nPydantic's `@field_validator` decorator enables custom validation logic for model fields.\n\n### Basic Validation\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Validation with Regex\n\n```python\nfrom pydantic import field_validator\n\nclass EmailModel(BaseModel):\n    email: str\n\n    @field_validator('email')\n    def validate_email_format(cls, v):\n        if '@' not in v:\n            raise ValueError('Invalid email format')\n        return v.lower()\n```\n\n## LLM Validators\n\nInstructor provides `llm_validator` for content-based validation using the LLM itself.\n\n### Setup\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BaseModel, BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n### Validation Workflow\n\n```mermaid\ngraph TD\n    A[LLM Generates Response] --> B[Apply BeforeValidator]\n    B --> C[LLM Validator Check]\n    C --> D{Validation Pass?}\n    D -->|Yes| E[Accept Response]\n    D -->|No| F[Raise Assertion Error]\n    F --> G[Retry with Context]\n```\n\n## Automatic Retries\n\nWhen validation fails, Instructor automatically retries the request with the error message included.\n\n### Retry Configuration\n\n```python\nqa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n    model=\"gpt-3.5-turbo\",\n    response_model=QuestionAnswerNoEvil,\n    max_retries=2,  # Number of retry attempts\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": \"You are a system that answers questions based on the context.\",\n        },\n        {\n            \"role\": \"user\",\n            \"content\": f\"using the context: {context}\\n\\nAnswer the following question: {question}\",\n        },\n    ],\n)\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n### Retry Behavior\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `max_retries` | `int` | `1` | Maximum number of retry attempts on validation failure |\n| `allow_override` | `bool` | `False` | Allows LLM to override validation with special flag |\n\n## Error Handling\n\n### Catching Validation Errors\n\n```python\ntry:\n    qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[\n            {\"role\": \"system\", \"content\": \"Answer questions based on context.\"},\n            {\"role\": \"user\", \"content\": f\"context: {context}\\nQuestion: {question}\"},\n        ],\n    )\nexcept Exception as e:\n    print(f\"Validation failed: {e}\")\n```\n\n### Error Output Example\n\n```\n1 validation error for QuestionAnswerNoEvil\nanswer\n    Assertion failed, The statement promotes sin and debauchery, which is objectionable.\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Supported Data Types\n\n| Type | Description | Example |\n|------|-------------|---------|\n| `str` | String text | `name: str` |\n| `int` | Integer numbers | `age: int` |\n| `float` | Decimal numbers | `price: float` |\n| `bool` | Boolean values | `is_active: bool` |\n| `list[T]` | Lists of type T | `tags: list[str]` |\n| `dict` | Dictionary objects | `metadata: dict` |\n| `enum` | Enumeration values | `status: Status` |\n| `Optional[T]` | Nullable values | `nickname: Optional[str]` |\n\n## Complete Example: User Extraction\n\n```python\nfrom instructor import from_provider\nfrom pydantic import BaseModel, field_validator\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n\n    @field_validator('email')\n    def validate_email(cls, v):\n        if '@' not in v:\n            raise ValueError('Invalid email address')\n        return v.lower()\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0 or v > 150:\n            raise ValueError('Age must be between 0 and 150')\n        return v\n\n# Automatic validation and retries\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"John is 35 years old, email: John@Example.com\"}],\n)\n\nprint(f\"Name: {user.name}\")      # John\nprint(f\"Age: {user.age}\")        # 35\nprint(f\"Email: {user.email}\")    # john@example.com\n```\n\n## Best Practices\n\n1. **Define clear schemas**: Use descriptive field names and type hints\n2. **Add validators early**: Catch invalid data at the source\n3. **Set appropriate retry limits**: Balance between reliability and cost\n4. **Use `allow_override` wisely**: Only when LLM feedback is acceptable\n5. **Handle exceptions**: Always wrap calls in try/except for production code\n\n## Related Concepts\n\n- [Fields Documentation](https://github.com/567-labs/instructor/blob/main/docs/concepts/fields.md) - Advanced field configuration\n- [Hooks System](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md) - Request/response lifecycle hooks\n- [Validations Examples](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md) - Custom validation patterns\n\n---\n\n<a id='validation-retries'></a>\n\n## Validation and Retry Mechanisms\n\n### 相关页面\n\n相关主题：[Response Models and Type Safety](#response-models), [Streaming and Partial Responses](#streaming)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# Validation and Retry Mechanisms\n\n## Overview\n\nInstructor provides robust validation and automatic retry mechanisms that work seamlessly with Pydantic models to ensure LLM outputs conform to expected schemas. When an LLM generates a response that fails validation, Instructor automatically retries the request with the validation error message included, allowing the model to self-correct its output.\n\nThe validation system extends beyond traditional Pydantic validators to include **LLM-based validators** that can check semantic content, tone, safety, and other qualitative aspects of generated text. Combined with automatic retries, this creates a feedback loop that significantly improves extraction reliability without requiring manual intervention.\n\n资料来源：[README.md:1-50]()\n\n---\n\n## Architecture\n\n### Core Components\n\n```mermaid\ngraph TD\n    A[Client Request] --> B[Pydantic Response Model]\n    B --> C[LLM API Call]\n    C --> D[Response Parsing]\n    D --> E{Validation}\n    E -->|Pass| F[Return Validated Object]\n    E -->|Fail| G[Log Error Message]\n    G --> H{Retry Count < max_retries?}\n    H -->|Yes| I[Retry with Error Context]\n    H -->|No| J[Raise Exception]\n    I --> C\n```\n\n### Validation Pipeline\n\n1. **Initial Request**: User submits a request with a Pydantic `response_model`\n2. **LLM Invocation**: Instructor calls the provider API with function calling parameters\n3. **Response Parsing**: Raw response is parsed into the target Pydantic model\n4. **Validation**: Pydantic validators run on the parsed data\n5. **Retry Decision**: If validation fails and retries remain, re-invoke with error context\n6. **Final Response**: Validated model instance is returned to user\n\n资料来源：[examples/validators/readme.md:1-80]()\n\n---\n\n## Pydantic-Based Validation\n\n### Standard Field Validators\n\nInstructor leverages Pydantic's built-in validation system. Fields defined in response models are automatically validated upon extraction:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\n### Validation Configuration\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `max_retries` | `int` | `3` | Maximum retry attempts after validation failure |\n| `response_model` | `BaseModel` | Required | Pydantic model defining expected output structure |\n| `validation_context` | `dict` | `None` | Additional context passed to validators |\n\n资料来源：[README.md:60-90]()\n\n---\n\n## LLM-Based Validation\n\n### Overview\n\nThe `llm_validator` function enables content-aware validation using the LLM itself. This is useful for semantic checks that cannot be expressed as simple schema rules:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n### How LLM Validation Works\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant Instructor\n    participant LLM\n    participant Validator\n    \n    User->>Instructor: Create response with llm_validator\n    Instructor->>LLM: Initial request\n    LLM-->>Instructor: Response\n    Instructor->>Validator: Validate content\n    Validator->>LLM: Check against constraint\n    alt Validation Passes\n        Validator-->>Instructor: Valid\n        Instructor-->>User: Return model\n    else Validation Fails\n        Validator-->>Instructor: Assertion failed: {reason}\n        Instructor->>LLM: Retry with error message\n        LLM-->>Instructor: Corrected response\n        Instructor->>Validator: Re-validate\n    end\n```\n\n### Validator Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `criteria` | `str` | The validation rule or constraint |\n| `allow_override` | `bool` | Whether the validator can be bypassed with `allow=True` |\n| `model` | `str` | Optional model to use for validation (defaults to response model) |\n\n资料来源：[examples/validators/readme.md:60-120]()\n\n---\n\n## Automatic Retry Mechanism\n\n### Retry Flow\n\nWhen validation fails, Instructor automatically retries the request. The retry process includes:\n\n1. **Error Capture**: The validation error message is extracted\n2. **Context Building**: Error details are formatted into a user message\n3. **Retry Execution**: The original request is repeated with error context\n4. **Iteration**: Process repeats until success or `max_retries` is exhausted\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=3,  # Retry up to 3 times\n)\n```\n\n### Retry Behavior\n\n| Scenario | Behavior |\n|----------|----------|\n| Validation passes | Return validated object immediately |\n| Validation fails (retries available) | Retry with error context |\n| Validation fails (no retries left) | Raise `ValidationError` |\n| API error | Retry with exponential backoff |\n\n资料来源：[README.md:75-95]()\n\n---\n\n## Streaming with Partial Validation\n\nInstructor supports streaming responses with partial validation, allowing real-time feedback as objects are generated:\n\n```python\nfrom instructor import Partial\n\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n):\n    print(partial_user)\n    # Output progression:\n    # User(name=None, age=None)\n    # User(name=\"John\", age=None)\n    # User(name=\"John\", age=25)\n```\n\n### Partial Validation States\n\n```mermaid\ngraph LR\n    A[Start] --> B{name != None}\n    B -->|No| C[Partial: User(name=None, ...)]\n    B -->|Yes| D{age != None}\n    D -->|No| E[Partial: User(name=\"...\", ...)]\n    D -->|Yes| F[Complete: User(...)]\n```\n\n资料来源：[README.md:95-110]()\n\n---\n\n## Hooks for Validation Monitoring\n\nInstructor provides hooks that allow monitoring of validation events during the request lifecycle:\n\n```mermaid\ngraph LR\n    A[Request Start] --> B[Parse Hook]\n    B --> C[LLM Call]\n    C --> D{Validation}\n    D --> E[Success Hook]\n    D --> F[Error Hook]\n    E --> G[Return Result]\n    F --> H[Retry Hook]\n    H -->|Has Retries| C\n    H -->|No Retries| I[Raise Exception]\n```\n\n### Available Hook Types\n\n| Hook | Trigger | Use Case |\n|------|---------|----------|\n| `on_request_start` | Before API call | Log request details |\n| `on_response` | Successful response | Track token usage |\n| `on_parse_error` | JSON parsing failure | Debug malformed output |\n| `on_retry` | Before retry attempt | Log retry attempts |\n| `on_validation_error` | Validation failure | Track failed validations |\n\n资料来源：[examples/hooks/README.md:1-30]()\n\n---\n\n## Error Handling Patterns\n\n### Handling Validation Errors\n\n```python\ntry:\n    qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    )\nexcept Exception as e:\n    print(f\"Validation failed after retries: {e}\")\n```\n\n### Common Validation Error Types\n\n| Error Type | Cause | Resolution |\n|------------|-------|------------|\n| `ValidationError` | Pydantic validation failure | Check field constraints |\n| `ParseError` | Malformed JSON response | Model may need adjustment |\n| `AssertionError` | LLM validator rejection | Review validation criteria |\n\n资料来源：[examples/validators/readme.md:100-140]()\n\n---\n\n## Integration with Batch Processing\n\nValidation and retry mechanisms are also available in batch processing scenarios:\n\n```python\nfrom instructor.processing import BatchProcessor\n\nbatch = BatchProcessor(\n    response_model=User,\n    max_retries=3,\n    on_validation_error=lambda e: log_error(e)\n)\n\nbatch.process(messages_file=\"messages.jsonl\")\n```\n\n### Batch Validation Features\n\n- Parallel validation of batch items\n- Per-item retry tracking\n- Aggregated error reporting\n- Configurable failure thresholds\n\n资料来源：[examples/batch_api/README.md:1-60]()\n\n---\n\n## Best Practices\n\n### 1. Define Clear Validation Rules\n\n```python\n# Good: Specific, enforceable rules\n@field_validator('email')\ndef validate_email(cls, v):\n    if '@' not in v:\n        raise ValueError('Invalid email format')\n    return v\n\n# Good: LLM validator for semantic checks\nllm_validator(\"response should be concise and factual\")\n```\n\n### 2. Set Appropriate Retry Limits\n\n| Use Case | Recommended `max_retries` |\n|----------|--------------------------|\n| Simple extraction | 1-2 |\n| Complex nested structures | 3-5 |\n| LLM-validated content | 2-3 |\n\n### 3. Use Descriptive Error Messages\n\nValidation error messages are passed to the LLM during retries. Clear, actionable error messages improve retry success rates.\n\n---\n\n## Summary\n\nInstructor's validation and retry mechanisms provide a powerful abstraction layer for reliable LLM output extraction:\n\n- **Pydantic Integration**: Leverage existing validation patterns\n- **LLM-Based Validation**: Check semantic content quality\n- **Automatic Retries**: Self-correcting extraction pipeline\n- **Streaming Support**: Real-time partial validation\n- **Hook System**: Observable validation lifecycle\n\nTogether, these components create a robust system for building production-grade LLM applications with predictable, validated outputs.\n\n资料来源：[README.md:1-120](), [examples/validators/readme.md:1-150]()\n\n---\n\n<a id='streaming'></a>\n\n## Streaming and Partial Responses\n\n### 相关页面\n\n相关主题：[Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [instructor/dsl/partial.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/partial.py)\n- [instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n- [docs/concepts/partial.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/partial.md)\n- [docs/concepts/iterable.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/iterable.md)\n- [examples/partial_streaming/run.py](https://github.com/567-labs/instructor/blob/main/examples/partial_streaming/run.py)\n</details>\n\n# Streaming and Partial Responses\n\n## Overview\n\nStreaming and partial responses are core features in Instructor that enable real-time processing of LLM outputs. Instead of waiting for the complete response to be generated, these features allow developers to receive and process data incrementally as it's being generated by the model.\n\nThe primary purpose of streaming support is to:\n- Provide faster perceived latency by displaying partial results immediately\n- Enable real-time UI updates for interactive applications\n- Support progressive data extraction for long-form content\n- Allow applications to start processing data before the entire response is complete\n\n资料来源：[README.md:streaming support]()\n\n## Architecture\n\nInstructor implements streaming through two complementary abstractions:\n\n1. **Partial** - Represents a partially validated response model\n2. **Iterable** - Represents a stream of validated response models\n\n### Data Flow Architecture\n\n```mermaid\ngraph TD\n    A[LLM API Streaming Response] --> B[Instructor Response Handler]\n    B --> C{Response Mode}\n    C -->|Partial Mode| D[Partial Validator]\n    C -->|Iterable Mode| E[Iterable Validator]\n    D --> F[Partial Response Model]\n    E --> G[Validated Response Objects]\n    F --> H[Application Consumer]\n    G --> H\n```\n\n### Component Overview\n\n| Component | Purpose | File Location |\n|-----------|---------|---------------|\n| `Partial[T]` | Generic wrapper for partial response models | `instructor/dsl/partial.py` |\n| `Iterable[T]` | Generic wrapper for streaming response models | `instructor/dsl/iterable.py` |\n| Response Handler | Processes streaming chunks from LLM providers | Core client implementation |\n| Validation Pipeline | Validates each partial/iterable chunk | Instructor DSL layer |\n\n资料来源：[instructor/dsl/partial.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/partial.py)\n资料来源：[instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n\n## Partial Responses\n\n### What Are Partial Responses?\n\nPartial responses enable receiving incrementally validated data as the LLM generates content. When using `Partial[T]`, each streamed chunk contains a validated response model where some fields may be `None` until the model finishes generating them.\n\n### Usage Pattern\n\n```python\nfrom instructor import Partial\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n# Stream partial responses as they're generated\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n):\n    print(partial_user)\n```\n\n### Evolution of Partial Response\n\nDuring streaming, the response model evolves as follows:\n\n```python\n# Initial state - no fields populated\n# User(name=None, age=None)\n\n# After name is generated\n# User(name=\"John\", age=None)\n\n# After full generation complete\n# User(name=\"John\", age=25)\n```\n\n资料来源：[README.md:Streaming support]()\n资料来源：[docs/concepts/partial.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/partial.md)\n\n## Iterable Responses\n\n### What Are Iterable Responses?\n\nIterable responses handle streams of complete, validated response models. Unlike `Partial[T]` which shows evolution of a single response, `Iterable[T]` represents multiple discrete responses that can be streamed from the LLM.\n\n### Usage Pattern\n\n```python\nfrom instructor import Iterable\n\nclass TaskResult(BaseModel):\n    task_id: str\n    result: str\n    status: str\n\n# Stream multiple validated responses\nfor task in client.chat.completions.create(\n    response_model=Iterable[TaskResult],\n    messages=[{\"role\": \"user\", \"content\": \"Process these items...\"}],\n    stream=True,\n):\n    print(f\"Task {task.task_id}: {task.status}\")\n```\n\n资料来源：[instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n资料来源：[docs/concepts/iterable.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/iterable.md)\n\n## API Reference\n\n### Client Method Signature\n\nBoth partial and iterable streaming use the standard client creation method with additional parameters:\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `response_model` | `Type[BaseModel]` | Required | The Pydantic model for validation |\n| `messages` | `List[dict]` | Required | Conversation messages |\n| `stream` | `bool` | `False` | Enable streaming mode |\n| `max_retries` | `int` | `3` | Maximum retry attempts on validation failure |\n| `**kwargs` | Various | Provider-specific | Additional provider parameters |\n\n### Response Type Resolution\n\n| Response Model Wrapper | Return Type | Use Case |\n|------------------------|-------------|----------|\n| `response_model=User` | `User` | Complete, validated single response |\n| `response_model=Partial[User]` | `Generator[User, None, None]` | Progressive single response |\n| `response_model=Iterable[User]` | `Generator[User, None, None]` | Stream of validated responses |\n\n资料来源：[examples/partial_streaming/run.py](https://github.com/567-labs/instructor/blob/main/examples/partial_streaming/run.py)\n\n## Provider Compatibility\n\n### Universal Streaming Support\n\nStreaming is supported across all major LLM providers through a unified interface:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n```\n\n### Provider Response Handling\n\nEach provider implements streaming through provider-specific response handlers:\n\n```mermaid\ngraph LR\n    A[Provider API] --> B[Provider Utils]\n    B --> C[Standardized Chunk Format]\n    C --> D[Instructor DSL]\n    D --> E[Partial/Iterable Validator]\n    E --> F[Validated Response]\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Validation Behavior\n\n### Validation During Streaming\n\nPartial and iterable responses undergo the same validation as non-streaming responses. The key difference is that validation occurs on each streamed chunk rather than on a complete response.\n\n### Validation Pipeline Flow\n\n```mermaid\ngraph TD\n    A[Stream Chunk Received] --> B[Parse to Response Model]\n    B --> C{Validation Pass?}\n    C -->|Yes| D[Yield Validated Partial]\n    C -->|No| E{Retry Available?}\n    E -->|Yes| F[Retry with Error Context]\n    E -->|No| G[Raise Validation Error]\n    D --> H[Next Chunk]\n    H --> A\n```\n\n### Error Handling\n\nWhen validation fails during streaming, Instructor can retry automatically if `max_retries` is configured:\n\n```python\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n    max_retries=3,  # Automatic retry on validation failure\n):\n    print(partial_user)\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Use Cases\n\n### Real-Time UI Updates\n\nPartial responses are ideal for applications requiring immediate visual feedback:\n\n```python\nfrom instructor import Partial\n\nclass SearchResult(BaseModel):\n    title: str\n    url: str\n    snippet: str\n\n# Update UI as results arrive\nfor partial_result in client.chat.completions.create(\n    response_model=Partial[SearchResult],\n    messages=[{\"role\": \"user\", \"content\": f\"Search for: {query}\"}],\n    stream=True,\n):\n    update_ui(partial_result)  # Progressive rendering\n```\n\n### Long-Running Task Processing\n\nIterable responses suit scenarios where the LLM generates multiple distinct outputs:\n\n```python\nclass AnalysisReport(BaseModel):\n    section: str\n    findings: List[str]\n    confidence: float\n\nfor report_section in client.chat.completions.create(\n    response_model=Iterable[AnalysisReport],\n    messages=[{\"role\": \"user\", \"content\": \"Analyze this document...\"}],\n    stream=True,\n):\n    save_section(report_section)\n```\n\n### Progressive Data Extraction\n\nExtract complex nested structures incrementally:\n\n```python\nclass Document(BaseModel):\n    title: str\n    author: str\n    sections: List[\"Section\"]\n\nclass Section(BaseModel):\n    heading: str\n    content: str\n\nfor partial_doc in client.chat.completions.create(\n    response_model=Partial[Document],\n    messages=[{\"role\": \"user\", \"content\": \"Extract document structure...\"}],\n    stream=True,\n):\n    display_preview(partial_doc)\n```\n\n## Best Practices\n\n### Performance Considerations\n\n| Practice | Recommendation | Rationale |\n|----------|----------------|-----------|\n| Batch Processing | Use `Iterable[T]` for multiple items | Reduces API call overhead |\n| UI Responsiveness | Prefer `Partial[T]` for progressive updates | Lower perceived latency |\n| Validation Overhead | Set appropriate `max_retries` | Balance reliability vs. performance |\n\n### Error Handling Strategy\n\n```python\ntry:\n    for partial in client.chat.completions.create(\n        response_model=Partial[User],\n        messages=[...],\n        stream=True,\n        max_retries=3,\n    ):\n        process(partial)\nexcept ValidationError as e:\n    handle_validation_failure(e)\nexcept Exception as e:\n    handle_stream_error(e)\n```\n\n### Memory Efficiency\n\nWhen processing large streams, consume the generator incrementally rather than collecting all results:\n\n```python\n# Memory efficient - processes one at a time\nfor item in client.chat.completions.create(\n    response_model=Iterable[LargeModel],\n    messages=[...],\n    stream=True,\n):\n    write_to_disk(item)\n\n# Memory intensive - collects all results\nall_items = list(client.chat.completions.create(\n    response_model=Iterable[LargeModel],\n    messages=[...],\n    stream=True,\n))\n```\n\n## Related Concepts\n\n- **Retry Logic**: Streaming integrates with Instructor's automatic retry mechanism for validation failures\n- **Hooks System**: Hooks can be attached to streaming operations for monitoring and logging\n- **Provider Architecture**: Each LLM provider implements streaming through provider-specific utilities\n\n## Summary\n\nStreaming and partial responses in Instructor provide powerful mechanisms for real-time data processing with LLM outputs. The `Partial[T]` wrapper enables progressive validation of single responses, while `Iterable[T]` supports streaming multiple discrete responses. Both features maintain full integration with Pydantic validation, retry logic, and all supported LLM providers through a unified API.\n\n---\n\n<a id='providers'></a>\n\n## LLM Provider Support\n\n### 相关页面\n\n相关主题：[Unified Provider Interface](#from-provider), [Installation and Setup](#installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# LLM Provider Support\n\n## Overview\n\nInstructor provides a unified API for working with multiple Large Language Model (LLM) providers. The library abstracts provider-specific implementations behind a common interface, allowing developers to switch between providers without modifying their application logic.\n\nThe `from_provider()` method serves as the primary entry point for initializing clients across all supported providers 资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md).\n\n## Supported Providers\n\nInstructor supports the following LLM providers through a consistent API:\n\n| Provider | Client Function | Model Examples |\n|----------|------------------|----------------|\n| OpenAI | `from_provider(\"openai/...\")` | gpt-4o, gpt-4o-mini, gpt-4-turbo |\n| Anthropic | `from_provider(\"anthropic/...\")` | claude-3-5-sonnet, claude-3-opus |\n| Google | `from_provider(\"google/...\")` | gemini-2.0-flash-001, gemini-pro |\n| Ollama | `from_provider(\"ollama/...\")` | llama3.2 (local models) |\n| Groq | `from_provider(\"groq/...\")` | llama-3.1-8b-instant |\n| Cohere | `from_provider(\"cohere/...\")` | Command R+ |\n| Mistral | `from_provider(\"mistral/...\")` | Mistral Large |\n| Fireworks | `from_provider(\"fireworks/...\")` | fireworks models |\n| Perplexity | `from_provider(\"perplexity/...\")` | perplexity models |\n| Cerebras | `from_provider(\"cerebras/...\")` | cerebras models |\n| XAI | `from_provider(\"xai/...\")` | xai models |\n| Writer | `from_provider(\"writer/...\")` | writer models |\n| VertexAI | `from_provider(\"vertexai/...\")` | vertexai models |\n| Bedrock | `from_provider(\"bedrock/...\")` | bedrock models |\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Provider Architecture\n\n### Directory Structure\n\nEach provider is organized in its own subdirectory within `instructor/providers/`:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Classification\n\nProviders are categorized based on their implementation complexity:\n\n#### Providers with Both `client.py` and `utils.py`\n\nThese providers require custom response handling logic and utility functions:\n\n- **anthropic**\n- **bedrock**\n- **cerebras**\n- **cohere**\n- **fireworks**\n- **gemini**\n- **mistral**\n- **perplexity**\n- **writer**\n- **xai**\n\n#### Providers with Only `client.py`\n\nThese are simpler providers using standard response handling from the core:\n\n- **genai**\n- **groq**\n- **vertexai**\n\n#### Special Case: OpenAI\n\nOpenAI doesn't have a `client.py` because `from_openai()` is defined in `core/client.py`. This is because OpenAI is the reference implementation that other providers are based on.\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Unified Client API\n\n### Basic Initialization\n\nAll providers use the same initialization pattern:\n\n```python\nclient = instructor.from_provider(\"provider/model-name\")\n```\n\n### Usage Example\n\n```python\nfrom instructor import from_provider\n\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### API Key Configuration\n\nAPI keys can be passed directly to the `from_provider()` method:\n\n```python\n# OpenAI with explicit API key\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\n\n# Anthropic with explicit API key\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n\n# Groq with explicit API key\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\nAlternatively, providers respect environment variables for API key configuration.\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Response Model Integration\n\nAll providers support Pydantic response models for structured outputs:\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Validator Support\n\nProviders work seamlessly with Pydantic validators:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### LLM Validators\n\nCustom validation using `llm_validator` is supported across all providers:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Automatic Retries\n\nFailed validations are automatically retried with the error message:\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=2,\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Batch Processing Support\n\nProviders support batch API operations through the unified `BatchProcessor` interface:\n\n### Supported Batch Operations\n\n```bash\n# Create batch using CLI\ninstructor batch create \\\n  --messages-file messages.jsonl \\\n  --model \"openai/gpt-4o-mini\" \\\n  --response-model \"examples.User\" \\\n  --output-file batch_requests.jsonl\n\n# Submit the batch\ninstructor batch create-from-file \\\n  --file-path batch_requests.jsonl \\\n  --model \"openai/gpt-4o-mini\"\n```\n\n### Provider-Specific Batch Features\n\n| Provider | Batch Endpoint | Notes |\n|----------|----------------|-------|\n| OpenAI | `client.batches.create()` | Standard batch API |\n| Anthropic | `client.beta.messages.batches` | Uses beta API endpoints |\n| Google | Simulation mode | Requires GCS for production |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Batch Test Script\n\nA test script is available to validate batch processing across providers:\n\n```bash\n# Test OpenAI\nexport OPENAI_API_KEY=\"your-api-key\"\npython run_batch_test.py create --model \"openai/gpt-4o-mini\"\n\n# Test Anthropic\nexport ANTHROPIC_API_KEY=\"your-api-key\"\npython run_batch_test.py create --model \"anthropic/claude-3-5-sonnet-20241022\"\n\n# Test Google (simulation mode)\npython run_batch_test.py create --model \"google/gemini-2.0-flash-001\"\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## Hooks System\n\nProviders integrate with Instructor's hooks system for monitoring and debugging:\n\n### Available Hook Events\n\n- **Request hooks**: Execute before API calls\n- **Response hooks**: Execute after successful responses\n- **Error hooks**: Execute on completion errors\n- **Retry hooks**: Execute on retry attempts\n\n### Hook Implementation Example\n\n```python\ndef on_request(detail):\n    print(f\"🔍 Request: {detail}\")\n\ndef on_response(detail):\n    print(f\"✅ Response: {detail}\")\n\ndef on_error(detail):\n    print(f\"❌ Error: {detail}\")\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient.attach_hook(\"request\", on_request)\nclient.attach_hook(\"response\", on_response)\nclient.attach_hook(\"error\", on_error)\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n## Fine-tuning Integration\n\nAll providers support Instructor's fine-tuning capabilities:\n\n```python\n# Generate fine-tuning data\npython three_digit_mul.py\n\n# Create fine-tuning job\ninstructor jobs create-from-file math_finetunes.jsonl\n\n# With validation data\ninstructor jobs create-from-file math_finetunes.jsonl \\\n  --n-epochs 4 \\\n  --validation-file math_finetunes_val.jsonl\n```\n\n资料来源：[examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n\n## Provider Selection Guidelines\n\n### Flowchart: Provider Selection\n\n```mermaid\ngraph TD\n    A[Select Provider] --> B{Need Local Model?}\n    B -->|Yes| C[Ollama]\n    B -->|No| D{Need Specific Capabilities?}\n    D -->|Anthropic Claude| E[Anthropic]\n    D -->|Google Gemini| F[Google]\n    D -->|OpenAI GPT| G[OpenAI]\n    D -->|Low Cost| H[Groq]\n    D -->|Custom| I[Other Providers]\n    G --> J[Create Client]\n    E --> J\n    F --> J\n    C --> J\n    H --> J\n    I --> J\n    J --> K[Use with Response Model]\n```\n\n### Selection Criteria\n\n| Use Case | Recommended Provider |\n|----------|---------------------|\n| General purpose, best quality | OpenAI GPT-4o |\n| Long context, reasoning | Anthropic Claude |\n| Fast inference, cost-effective | Groq |\n| Multimodal capabilities | Google Gemini |\n| Local/private deployment | Ollama |\n| AWS integration | Bedrock |\n| Complex reasoning tasks | xAI |\n\n## Adding New Providers\n\nWhen adding a new provider to Instructor:\n\n1. Create a new subdirectory under `instructor/providers/`\n2. Add an `__init__.py` file\n3. Implement `client.py` for the provider factory function\n4. Add `utils.py` for provider-specific response handling\n5. Update the unified `from_provider()` dispatcher\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Error Handling\n\n### Common Provider Errors\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `API key not set` | Missing environment variable | Set appropriate API key |\n| `Invalid model format` | Incorrect model string format | Use `provider/model-name` format |\n| `Unsupported provider` | Provider not in registry | Use supported provider names |\n| `Rate limit exceeded` | Too many requests | Implement backoff or reduce concurrency |\n\n### Error Recovery\n\nProviders support automatic retry with exponential backoff for transient failures:\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=3,\n)\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## See Also\n\n- [Core Client Implementation](../instructor/client.md)\n- [Response Models and Validation](./response_models.md)\n- [Hooks System](./hooks.md)\n- [Batch Processing](./batch_processing.md)\n- [Fine-tuning](./fine_tuning.md)\n\n---\n\n<a id='from-provider'></a>\n\n## Unified Provider Interface\n\n### 相关页面\n\n相关主题：[LLM Provider Support](#providers), [Core Components Architecture](#core-components)\n\n<details>\n<summary>Related Source Files</summary>\n\nThe following source files were referenced (note: some files were not available in the current context):\n\n- [instructor/auto_client.py](https://github.com/567-labs/instructor/blob/main/instructor/auto_client.py) - Main unified client implementation\n- [docs/concepts/from_provider.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/from_provider.md) - Conceptual documentation for the provider interface\n- [instructor/utils/providers.py](https://github.com/567-labs/instructor/blob/main/instructor/utils/providers.py) - Provider utility functions\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md) - Primary documentation\n- [providers/README.md](https://github.com/567-labs/instructor/blob/main/providers/README.md) - Provider organization documentation\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md) - Batch API with provider examples\n\n</details>\n\n# Unified Provider Interface\n\n## Overview\n\nThe **Unified Provider Interface** is a core architectural feature of the Instructor library that provides a single, consistent API for interacting with multiple Large Language Model (LLM) providers. This abstraction eliminates provider-specific code patterns and allows developers to switch between different LLM backends without modifying their application logic.\n\nThe unified interface is accessed through the `from_provider()` factory function, which accepts provider/model strings in the format `\"provider/model-name\"` and returns a configured client instance that follows a standardized interface. 资料来源：[README.md](README.md)\n\n## Architecture\n\n### Core Design Principles\n\n1. **Provider Agnosticism**: All supported providers implement the same method signatures\n2. **Automatic Model Detection**: Provider is inferred from the model string prefix\n3. **Transparent Retries**: Failed validations are automatically retried with error context\n4. **Type Safety**: Full Pydantic integration for response validation\n\n### Supported Providers\n\nThe unified interface supports multiple LLM providers through a consistent abstraction layer:\n\n| Provider | Model Prefix | Special Features |\n|----------|--------------|------------------|\n| OpenAI | `openai/` | Reference implementation |\n| Anthropic | `anthropic/` | Beta API endpoints |\n| Google | `google/` | Gemini Pro/Vision |\n| Ollama | `ollama/` | Local models |\n| Groq | `groq/` | Fast inference |\n| Mistral | `mistral/` | European models |\n| Cohere | `cohere/` | Command models |\n| AWS Bedrock | `bedrock/` | Cloud deployment |\n| Cerebras | `cerebras/` | Optimized inference |\n| Fireworks | `fireworks/` | High performance |\n| Perplexity | `perplexity/` | Search-focused |\n| Writer | `writer/` | Enterprise content |\n| XAI | `xai/` | Elon Musk's xAI |\n\n资料来源：[README.md](README.md), [providers/README.md](providers/README.md)\n\n## Usage\n\n### Basic Initialization\n\n```python\nimport instructor\n\n# Create unified client for any provider\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Use the same API regardless of provider\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n### Provider Comparison\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md](README.md)\n\n### API Key Configuration\n\nThe unified interface supports multiple ways to provide API credentials:\n\n| Method | Description |\n|--------|-------------|\n| Environment Variables | `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc. |\n| Direct Parameter | `client = from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")` |\n\n```python\n# With API keys directly (no environment variables needed)\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\n资料来源：[README.md](README.md)\n\n## Provider Directory Structure\n\nEach provider implementation follows a standardized directory structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n### Provider Categories\n\n**Providers with both `client.py` and `utils.py`:**\n- anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai\n\n**Providers with only `client.py`:**\n- genai, groq, vertexai\n\n**Special Case - OpenAI:**\n- OpenAI doesn't have a `client.py` because `from_openai()` is defined in `core/client.py`\n- OpenAI is the reference implementation that other providers are based on\n\n资料来源：[providers/README.md](providers/README.md)\n\n## API Methods\n\n### Create Method\n\nThe primary method for generating structured responses:\n\n```python\nresponse = client.chat.completions.create(\n    response_model=User,  # Pydantic model\n    messages=[...],\n    model=\"...\",\n    max_retries=3,  # Automatic retry on validation failure\n)\n```\n\n### Alternative API Patterns\n\nFor simplified usage, these patterns are also supported:\n\n```python\n# All equivalent to client.chat.completions.create\nclient.create()\nclient.create_partial()\nclient.create_iterable()\nclient.create_with_completion()\n```\n\n资料来源：[scripts/README.md](scripts/README.md)\n\n## Response Model Integration\n\nThe unified interface seamlessly integrates with Pydantic for type validation:\n\n### Basic Model Definition\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n### Model with Validation\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\nWhen validation fails, Instructor automatically retries the request with the error message:\n\n```python\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](README.md)\n\n## Batch Processing\n\nThe unified interface supports batch processing across all providers through the `BatchProcessor` class:\n\n```python\nfrom instructor.batch import BatchProcessor\n\nprocessor = BatchProcessor()\n\n# Create batch with provider detection\nprocessor.create_batch(\n    messages=test_messages,\n    model=\"openai/gpt-4o-mini\",\n    response_model=User,\n)\n```\n\n### Provider-Specific Batch Support\n\n| Provider | Batch API | Notes |\n|----------|-----------|-------|\n| OpenAI | `client.batches.create()` | Full support |\n| Anthropic | `client.beta.messages.batches` | Beta endpoints |\n| Google | Simulation mode | Requires GCS setup |\n\n资料来源：[examples/batch_api/README.md](examples/batch_api/README.md)\n\n## Workflow Diagram\n\n```mermaid\ngraph TD\n    A[User Code] --> B[from_provider factory]\n    B --> C{Parse provider/model}\n    C -->|openai| D[OpenAI Client]\n    C -->|anthropic| E[Anthropic Client]\n    C -->|google| F[Google Client]\n    C -->|other| G[Other Provider Client]\n    \n    D --> H[Unified API Layer]\n    E --> H\n    F --> H\n    G --> H\n    \n    H --> I[Provider-Specific Transport]\n    I --> J{Response Validation}\n    J -->|Pass| K[Return Typed Response]\n    J -->|Fail| L[Retry with Error Context]\n    L --> H\n```\n\n## Advanced Configuration\n\n### Custom Validators\n\nYou can add custom LLM-based validation:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n### Retry Configuration\n\n```python\n# Allow retries on validation failure\nqa = client.chat.completions.create(\n    response_model=QuestionAnswer,\n    max_retries=2,\n    messages=[...],\n)\n```\n\n资料来源：[examples/validators/readme.md](examples/validators/readme.md)\n\n## Migration from Legacy Patterns\n\n### Old Patterns to Unified Interface\n\n| Old Pattern | Unified Pattern |\n|-------------|------------------|\n| `instructor.from_openai(OpenAI())` | `instructor.from_provider(\"openai/model-name\")` |\n| `instructor.from_anthropic(Anthropic())` | `instructor.from_provider(\"anthropic/model-name\")` |\n| `instructor.patch(OpenAI())` | `instructor.from_provider(\"openai/model-name\")` |\n\n### Automated Migration Scripts\n\nThe repository includes scripts to automate migration:\n\n```bash\n# Replace old patterns automatically\npython scripts/fix_old_patterns.py --dry-run\npython scripts/fix_old_patterns.py\n\n# Audit documentation for old patterns\npython scripts/audit_patterns.py\n```\n\n资料来源：[scripts/README.md](scripts/README.md)\n\n## Summary\n\nThe Unified Provider Interface is a fundamental architectural feature that enables Instructor to work seamlessly across multiple LLM providers. By abstracting provider-specific details behind a common API:\n\n- Developers can switch providers without code changes\n- Response validation works consistently across all providers\n- Automatic retries provide resilience against transient failures\n- The Pydantic integration ensures type safety throughout\n\nThis design philosophy makes Instructor highly adaptable and future-proof, as new providers can be added without affecting existing code.\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：567-labs/instructor\n\n摘要：发现 21 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：安装坑 - 来源证据：Documentation (at least Google-related) is an outdated mess.。\n\n## 1. 安装坑 · 来源证据：Documentation (at least Google-related) is an outdated mess.\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Documentation (at least Google-related) is an outdated mess.\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b87b003416cd4308bc863f0cd66a68fd | https://github.com/567-labs/instructor/issues/2289 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v1.13.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v1.13.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f3c1e8416a744b51b5691317c10bc5bf | https://github.com/567-labs/instructor/releases/tag/v1.13.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 配置坑 · 来源证据：v1.12.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.12.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9b8236f58f8641c586777618a838409f | https://github.com/567-labs/instructor/releases/tag/v1.12.0 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 4. 配置坑 · 来源证据：v1.14.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_053ef3382ace48778d05ef006d87cead | https://github.com/567-labs/instructor/releases/tag/v1.14.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 来源证据：v1.14.3\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.3\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_d18c003929614c7097d16742ec94cc8c | https://github.com/567-labs/instructor/releases/tag/v1.14.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 6. 配置坑 · 来源证据：v1.14.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.4\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_76987134f9a747d685958a5e98f3b51a | https://github.com/567-labs/instructor/releases/tag/v1.14.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：v1.15.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.15.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_430369db61e440e5a4b575e2b3618464 | https://github.com/567-labs/instructor/releases/tag/v1.15.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 8. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:653589102 | https://github.com/567-labs/instructor | README/documentation is current enough for a first validation pass.\n\n## 9. 运行坑 · 来源证据：v1.14.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个运行相关的待验证问题：v1.14.2\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_fd561faf78f147518bcda7a0370a9a4f | https://github.com/567-labs/instructor/releases/tag/v1.14.2 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：Catching IncompleteOutputException : not possible as presently documented / tested.\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Catching IncompleteOutputException : not possible as presently documented / tested.\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dc0f4256859740f8a4cacd1731514783 | https://github.com/567-labs/instructor/issues/2273 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b982358c78a346bfaa26b428e00968bb | https://github.com/567-labs/instructor/issues/2291 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：bump lightllm upper bound for recent vulnerabililties\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bump lightllm upper bound for recent vulnerabililties\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2ae9c53479204c778e56a8b4b3feb404 | https://github.com/567-labs/instructor/issues/2290 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 16. 安全/权限坑 · 来源证据：logger.debug in response.py leaks api_key verbatim via new_kwargs\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：logger.debug in response.py leaks api_key verbatim via new_kwargs\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2076a35fb27a4c119141e9f57acdf9bc | https://github.com/567-labs/instructor/issues/2265 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 17. 安全/权限坑 · 来源证据：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry m…\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry message\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_0ab343e8383b4d89bbe8eeea25cc69d8 | https://github.com/567-labs/instructor/issues/2277 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 18. 安全/权限坑 · 来源证据：v1.14.5\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.14.5\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_e73ef57918504fe88cf0af969c414ca1 | https://github.com/567-labs/instructor/releases/tag/v1.14.5 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v1.15.1\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.15.1\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_ef102fc17ae84e319f80cfd4cc306eaa | https://github.com/567-labs/instructor/releases/tag/v1.15.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | issue_or_pr_quality=unknown\n\n## 21. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | release_recency=unknown\n\n<!-- canonical_name: 567-labs/instructor; human_manual_source: deepwiki_human_wiki -->\n",
      "markdown_key": "instructor",
      "pages": "draft",
      "source_refs": [
        {
          "evidence_id": "github_repo:653589102",
          "kind": "repo",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/567-labs/instructor"
        },
        {
          "evidence_id": "art_011c606e51c94959817c7bc10ccb55af",
          "kind": "docs",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/567-labs/instructor#readme"
        }
      ],
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "instructor 说明书",
      "toc": [
        "https://github.com/567-labs/instructor 项目说明书",
        "目录",
        "Introduction to Instructor",
        "Overview",
        "Core Concepts",
        "Instructor automatically retries when validation fails",
        "Supported Providers",
        "Installation",
        "Doramagic 踩坑日志"
      ]
    }
  },
  "quality_gate": {
    "blocking_gaps": [],
    "category_confidence": "medium",
    "compile_status": "ready_for_review",
    "five_assets_present": true,
    "install_sandbox_verified": true,
    "missing_evidence": [],
    "next_action": "publish to Doramagic.ai project surfaces",
    "prompt_preview_boundary_ok": true,
    "publish_status": "publishable",
    "quick_start_verified": true,
    "repo_clone_verified": true,
    "repo_commit": "5e8e2d57e791ed505c9637c0e215b10a5441b66a",
    "repo_inspection_error": null,
    "repo_inspection_files": [
      "pyproject.toml",
      "README.md",
      "uv.lock",
      "requirements.txt",
      "docs/why.md",
      "docs/architecture.md",
      "docs/contributing.md",
      "docs/newsletter.md",
      "docs/debugging.md",
      "docs/index.md",
      "docs/api.md",
      "docs/repository-overview.md",
      "docs/getting-started.md",
      "docs/api-docstring-assessment.md",
      "docs/installation.md",
      "docs/modes-comparison.md",
      "docs/start-here.md",
      "docs/faq.md",
      "docs/help.md",
      "docs/jobs.md",
      "docs/AGENT.md",
      "docs/cli/finetune.md",
      "docs/cli/index.md",
      "docs/cli/batch.md",
      "docs/cli/usage.md",
      "docs/blog/index.md",
      "docs/blog/.authors.yml",
      "docs/hooks/hide_lines.py",
      "docs/concepts/iterable.md",
      "docs/concepts/typeadapter.md",
      "docs/concepts/lists.md",
      "docs/concepts/philosophy.md",
      "docs/concepts/prompt_caching.md",
      "docs/concepts/index.md",
      "docs/concepts/dictionary_operations.md",
      "docs/concepts/prompting.md",
      "docs/concepts/reask_validation.md",
      "docs/concepts/templating.md",
      "docs/concepts/citation.md",
      "docs/concepts/logging.md"
    ],
    "repo_inspection_verified": true,
    "review_reasons": [],
    "tag_count_ok": true,
    "unsupported_claims": []
  },
  "schema_version": "0.1",
  "user_assets": {
    "ai_context_pack": {
      "asset_id": "ai_context_pack",
      "filename": "AI_CONTEXT_PACK.md",
      "markdown": "# instructor - Doramagic AI Context Pack\n\n> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。\n\n## 充分原则\n\n- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。\n- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。\n\n## 给宿主 AI 的使用方式\n\n你正在读取 Doramagic 为 instructor 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。\n\n## Claim 消费规则\n\n- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。\n- **事实最低状态**：`supported`\n- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。\n- `weak`：只能作为低置信度线索，必须要求用户继续核实。\n- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。\n- `unverified`：不得作为事实使用，应明确说证据不足。\n- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。\n\n## 它最适合谁\n\n- **正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**：README 或插件配置提到多个宿主 AI。 证据：`README.md` Claim：`clm_0002` supported 0.86\n\n## 它能做什么\n\n- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`CLAUDE.md`, `README.md` Claim：`clm_0001` supported 0.86\n\n## 怎么开始\n\n- `pip install instructor` 证据：`README.md` Claim：`clm_0003` supported 0.86, `clm_0005` supported 0.86, `clm_0006` supported 0.86, `clm_0007` supported 0.86\n- `pip install -r requirements-doc.txt` 证据：`CLAUDE.md` Claim：`clm_0004` supported 0.86\n- `pip install \"instructor[anthropic]\"` 证据：`CLAUDE.md` Claim：`clm_0005` supported 0.86\n- `pip install \"instructor[google-generativeai]\"` 证据：`CLAUDE.md` Claim：`clm_0006` supported 0.86\n- `pip install \"instructor[groq]\"` 证据：`CLAUDE.md` Claim：`clm_0007` supported 0.86\n\n## 继续前判断卡\n\n- **当前建议**：先做角色匹配试用\n- **为什么**：这个项目更像角色库，核心风险是选错角色或把角色文案当执行能力；先用 Prompt Preview 试角色匹配，再决定是否沙盒导入。\n\n### 30 秒判断\n\n- **现在怎么做**：先做角色匹配试用\n- **最小安全下一步**：先用 Prompt Preview 试角色匹配；满意后再隔离导入\n- **先别相信**：角色质量和任务匹配不能直接相信。\n- **继续会触碰**：角色选择偏差、命令执行、宿主 AI 配置\n\n### 现在可以相信\n\n- **适合人群线索：正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86\n- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`CLAUDE.md`, `README.md` Claim：`clm_0001` supported 0.86\n- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0003` supported 0.86, `clm_0005` supported 0.86, `clm_0006` supported 0.86, `clm_0007` supported 0.86\n\n### 现在还不能相信\n\n- **角色质量和任务匹配不能直接相信。**（unverified）：角色库证明有很多角色，不证明每个角色都适合你的具体任务，也不证明角色能产生高质量结果。\n- **不能把角色文案当成真实执行能力。**（unverified）：安装前只能判断角色描述和任务画像是否匹配，不能证明它能在宿主 AI 里完成任务。\n- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。\n- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。\n- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。 证据：`CLAUDE.md`\n- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。\n- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。\n- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。\n\n### 继续会触碰什么\n\n- **角色选择偏差**：用户对任务应该由哪个专家角色处理的判断。 原因：选错角色会让 AI 从错误专业视角回答，浪费时间或误导决策。\n- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`CLAUDE.md`, `README.md`\n- **宿主 AI 配置**：Claude/Codex/Cursor/Gemini/OpenCode 等宿主的 plugin、Skill 或规则加载配置。 原因：宿主配置会改变 AI 后续工作方式，可能和用户已有规则冲突。 证据：`CLAUDE.md`\n- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`CLAUDE.md`, `README.md`\n- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。\n\n### 最小安全下一步\n\n- **先跑 Prompt Preview**：先用交互式试用验证任务画像和角色匹配，不要先导入整套角色库。（适用：任何项目都适用，尤其是输出质量未知时。）\n- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）\n- **先备份宿主 AI 配置**：Skill、plugin、规则文件可能改变 Claude/Cursor/Codex 的默认行为。（适用：存在插件 manifest、Skill 或宿主规则入口时。）\n- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）\n\n### 退出方式\n\n- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。\n- **准备移除宿主 plugin / Skill / 规则入口**：如果试装后行为异常，可以把宿主 AI 恢复到试装前状态。\n- **保留原始角色选择记录**：如果输出偏题，可以回到任务画像阶段重新选择角色，而不是继续沿着错误角色推进。\n- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。\n- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。\n\n## 哪些只能预览\n\n- 解释项目适合谁和能做什么\n- 基于项目文档演示典型对话流程\n- 帮助用户判断是否值得安装或继续研究\n\n## 哪些必须安装后验证\n\n- 真实安装 Skill、插件或 CLI\n- 执行脚本、修改本地文件或访问外部服务\n- 验证真实输出质量、性能和兼容性\n\n## 边界与风险判断卡\n\n- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0008` inferred 0.45\n- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`CLAUDE.md`, `README.md` Claim：`clm_0009` supported 0.86\n- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。\n- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。\n- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。\n\n## 开工前工作上下文\n\n### 加载顺序\n\n- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。\n- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。\n- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。\n- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。\n- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。\n\n### 任务路由\n\n- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`CLAUDE.md`, `README.md` Claim：`clm_0001` supported 0.86\n\n### 上下文规模\n\n- 文件总数：712\n- 重要文件覆盖：40/712\n- 证据索引条目：79\n- 角色 / Skill 条目：79\n\n### 证据不足时的处理\n\n- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。\n- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。\n- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。\n- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。\n\n## Prompt Recipes\n\n### 适配判断\n\n- 目标：判断这个项目是否适合用户当前任务。\n- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。\n\n```text\n请基于 instructor 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。\n```\n\n### 安装前体验\n\n- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。\n- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。\n\n```text\n请把 instructor 当作安装前体验资产，而不是已安装工具或真实运行环境。\n\n请严格输出四段：\n1. 先问我 3 个必要问题。\n2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。\n3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。\n4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。\n\n硬性边界：\n- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。\n- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。\n- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。\n- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。\n- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。\n- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。\n\n```\n\n### 角色 / Skill 选择\n\n- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。\n- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。\n\n```text\n请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。\n```\n\n### 风险预检\n\n- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。\n- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。\n\n```text\n请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。\n```\n\n### 宿主 AI 开工指令\n\n- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。\n- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。\n\n```text\n请基于 instructor 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。\n```\n\n\n## 角色 / Skill 索引\n\n- 共索引 79 个角色 / Skill / 项目文档条目。\n\n- **Contributing to Instructor**（project_doc）：Join us in enhancing the Instructor library with evals, report issues, and submit pull requests on GitHub. Collaborate and contribute! 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/contributing.md`\n- **CLAUDE.md**（project_doc）：This file provides guidance to Claude Code claude.ai/code when working with code in this repository. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CLAUDE.md`\n- **Instructor: Structured Outputs for LLMs**（project_doc）：Instructor: Structured Outputs for LLMs 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`\n- **Scripts Directory**（project_doc）：This directory contains utility scripts for maintaining and improving the Instructor documentation and project structure. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`scripts/README.md`\n- **Cursor Rules**（project_doc）：Cursor rules are configuration files that help guide AI-assisted development in the Cursor IDE. They provide structured instructions for how the AI should behave in specific contexts or when working with certain types of files. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`.cursor/rules/readme.md`\n- **Batch API Examples**（project_doc）：This directory contains examples and test scripts for Instructor's batch processing capabilities, including both traditional file-based and new in-memory processing. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/batch_api/README.md`\n- **Instructor Caching Prototype**（project_doc）：This example demonstrates the new built-in caching functionality in Instructor. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/caching_prototype/README.md`\n- **Introduction**（project_doc）：This is a simple example which shows how to perform Chain Of Density summarization using GPT-3.5 and utilise the generated output to fine-tune a 3.5 model for production usage. All of our data referenced in this file is located here https://huggingface.co/datasets/ivanleomk/gpt4-chain-of-density on hugging face 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/chain-of-density/Readme.md`\n- **Citation with Extraction**（project_doc）：This repository contains a FastAPI application that uses GPT-4 to answer questions based on a given context and extract relevant facts with correct and exact citations. The extracted facts are returned as JSON events using Server-Sent Events SSE . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/citation_with_extraction/README.md`\n- **FastAPI Code Generator**（project_doc）：Generates FastAPI application code from API path, task name, JSON schema path, and Jinja2 prompt template. Also creates a models.py file for Pydantic models. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/codegen-from-schema/readme.md`\n- **What to Expect**（project_doc）：What to Expect This script demonstrates how to use the Instructor library for fine-tuning a Python function that performs three-digit multiplication. It uses Pydantic for type validation and logging features to generate a fine-tuning dataset. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/distilations/readme.md`\n- **Instructor Hooks Example**（project_doc）：This example demonstrates how to use the Hooks system in the Instructor library to monitor, log, and debug your LLM interactions. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/hooks/README.md`\n- **Instructions**（project_doc）：1. Create a virtual environment and install all of the packages inside requirements.txt 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/logfire-fastapi/Readme.md`\n- **Read first to correctly work with the provided examples**（project_doc）：Read first to correctly work with the provided examples 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/open_source_examples/README.md`\n- **Using llm validator with OpenAI's GPT-3.5 Turbo and Pydantic for Text Validation with Output Examples**（project_doc）：Using llm validator with OpenAI's GPT-3.5 Turbo and Pydantic for Text Validation with Output Examples 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/validators/readme.md`\n- **Providers Directory Structure**（project_doc）：This directory contains implementations for all supported LLM providers in the instructor library. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`instructor/providers/README.md`\n- **Contributing to Instructor**（project_doc）：Thank you for considering contributing to Instructor! This document provides guidelines and instructions to help you contribute effectively. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CONTRIBUTING.md`\n- **Core Provider Tests**（project_doc）：This directory contains unified tests that run across all core providers : OpenAI, Anthropic, Google Gemini , Cohere, xAI, Mistral, Cerebras, Fireworks, Writer, and Perplexity. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`tests/llm/test_core_providers/README.md`\n- **AGENT.md - Documentation**（project_doc）：Internal guide for maintaining and improving Instructor documentation 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/AGENT.md`\n- **API Docstring Quality Assessment**（project_doc）：This document assesses the quality and completeness of docstrings for all API items referenced in the expanded API documentation. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/api-docstring-assessment.md`\n- **API Reference**（project_doc）：Explore the comprehensive API reference with details on instructors, validation, iteration, and function calls. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/api.md`\n- **Architecture Overview**（project_doc）：Learn about the internal architecture and design decisions of the Instructor library 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/architecture.md`\n- **Debugging**（project_doc）：Learn how to debug Instructor applications with hooks, logging, and exception handling. Practical techniques for inspecting inputs, outputs, and retries. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/debugging.md`\n- **Frequently Asked Questions**（project_doc）：Common questions and answers about using Instructor 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/faq.md`\n- **Getting Started with Instructor**（project_doc）：A step-by-step guide to getting started with Instructor for structured outputs from LLMs 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/getting-started.md`\n- **Getting help with Instructor**（project_doc）：Explore key resources for getting help with Instructor, including Discord, blog, concepts, cookbooks, and GitHub discussions. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/help.md`\n- **Instructor: Top Multi-Language Library for Structured LLM Outputs**（project_doc）：Get structured, validated data from any LLM with Instructor - the 1 library for LLM data extraction. Supports 15+ providers OpenAI, Anthropic, Google, Ollama, DeepSeek in 6 languages. Built on type-safe schemas with automatic retries, streaming, and nested object support. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/index.md`\n- **Installation**（project_doc）：Learn how to install Instructor and its dependencies using pip for Python 3.9+. Simple setup guide included. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/installation.md`\n- **Jobs**（project_doc）： 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/jobs.md`\n- **Instructor Mode Comparison Guide**（project_doc）：Compare different modes available in Instructor and understand when to use each 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/modes-comparison.md`\n- **Instructor Newsletter**（project_doc）：Get notified about AI tips, blog posts, and research. Stay informed with Instructor's latest features and community insights. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/newsletter.md`\n- **Repository Overview**（project_doc）：Learn the structure of the Instructor repository and the purpose of each major directory. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/repository-overview.md`\n- **Start Here: Instructor for Beginners**（project_doc）：A beginner-friendly introduction to using Instructor for structured outputs from LLMs 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/start-here.md`\n- **Why use Instructor?**（project_doc）：Discover why Instructor is the simplest, most reliable way to get structured outputs from LLMs. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/why.md`\n- **Subscribe to our Newsletter for Updates and Tips**（project_doc）：Subscribe to our Newsletter for Updates and Tips 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/index.md`\n- **AI Engineer Keynote: Pydantic is all you need**（project_doc）：Explore insights on utilizing Pydantic for effective prompt engineering 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/aisummit-2023.md`\n- **Structured Outputs for Gemini now supported**（project_doc）：Introducing structured outputs for Gemini tool calling support in the 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/announcing-gemini-tool-calling-support.md`\n- **Announcing Responses API support**（project_doc）：Take advantage of OpenAI's latest offerings with the new responses API 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/announcing-instructor-responses-support.md`\n- **What is from provider ?**（project_doc）：Switch between different models and providers with a single string! 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/announcing-unified-provider-interface.md`\n- **Why should I use prompt caching?**（project_doc）：Discover how prompt caching with Anthropic can improve response times 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/anthropic-prompt-caching.md`\n- **Using Anthropic's Web Search with Instructor for Real-Time Data**（project_doc）：Using Anthropic's Web Search with Instructor for Real-Time Data 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/anthropic-web-search-structured.md`\n- **Structured Outputs with Anthropic**（project_doc）：Learn how to integrate Anthropic's powerful language models into your projects using Instructor, with step-by-step guidance on installation, client setup, and creating structured outputs with Pydantic models. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/anthropic.md`\n- **Bad Schemas could break your LLM Structured Outputs**（project_doc）：Discover how response models impact LLM performance, focusing on structured 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/bad-schemas-could-break-llms.md`\n- **Why Instructor is the Best Library for Structured LLM Outputs**（project_doc）：Discover how the Instructor library simplifies structured LLM outputs 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/best_framework.md`\n- **Advanced Caching Strategies for Python LLM Applications Validated & Tested ✅**（project_doc）：Master advanced Python caching strategies for LLM applications using functools, diskcache, and Redis. Learn how to optimize OpenAI API costs, reduce response times, and implement efficient caching for Pydantic models in production environments. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/caching.md`\n- **Smarter Summaries w/ Finetuning GPT-3.5 and Chain of Density**（project_doc）：Learn to implement Chain of Density with GPT-3.5 for improved summarization, 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/chain-of-density.md`\n- **PDF Processing with Structured Outputs with Gemini**（project_doc）：Learn how to use Google's Gemini model with Instructor to process PDFs and extract structured information 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/chat-with-your-pdf-with-gemini.md`\n- **Verifying LLM Citations with Pydantic**（project_doc）：Explore how Pydantic enhances LLM citation verification, improving data 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/citations.md`\n- **Consistent Stories with GPT-4o**（project_doc）：Generating complex DAGS with gpt-4o 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/consistent-stories.md`\n- **Free course on Weights and Biases**（project_doc）：Discover a free one-hour course on Weights and Biases covering essential 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/course.md`\n- **Instructor Adopting Cursor Rules**（project_doc）：AI-assisted coding is changing how we use version control. Many developers now use what I call \"vibe coding\" - coding with AI help. This creates new challenges with Git. Today I'll share how we're using Cursor rules in Instructor to solve these problems. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/cursor-rules.md`\n- **Enhancing Python Functions with Instructor: A Guide to Fine-Tuning and Distillation**（project_doc）：Explore Instructor for fine-tuning language models with Python, simplifying 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/distilation-part1.md`\n- **Consistent Stories with GPT-4o**（project_doc）：Generating complex DAGS with gpt-4o 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/extract-model-looks.md`\n- **Why Image Metadata is useful**（project_doc）：Structured Extraction makes working with images easy, in this post we'll see how to use it to extract metadata from images 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/extracting-model-metadata.md`\n- **Simple Synthetic Data Generation**（project_doc）：Learn to generate synthetic data using Pydantic and OpenAI's models with 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/fake-data.md`\n- **Why Logfire is a perfect fit for FastAPI + Instructor**（project_doc）：Discover how Logfire enhances FastAPI applications with OpenTelemetry 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/full-fastapi-visibility.md`\n- **Eliminating Hallucinations with Structured Outputs using Gemini**（project_doc）：Generate accurate citations and eliminate hallucinations with structured outputs using Gemini. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/generating-pdf-citations.md`\n- **Generators and LLM Streaming**（project_doc）：Explore Python generators and their role in enhancing LLM streaming for 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/generator.md`\n- **Do I Still Need Instructor with Google's New OpenAI Integration?**（project_doc）：Learn why Instructor remains essential even with Google's new OpenAI-compatible client for Gemini 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/google-openai-client.md`\n- **Introducing structured outputs with Cerebras Inference**（project_doc）：Introducing structured outputs with Cerebras Inference 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/introducing-structured-outputs-with-cerebras-inference.md`\n- **Should I Be Using Structured Outputs?**（project_doc）：Explore the challenges of OpenAI's Structured Outputs and how 'instructor 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/introducing-structured-outputs.md`\n- **Generating Structured Output / JSON from LLMs**（project_doc）：Learn how Pydantic simplifies working with LLMs and structured JSON outputs 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/introduction.md`\n- **Instructor Proposal: Integrating Jinja Templating**（project_doc）：Explore the integration of Jinja templating in the Instructor for enhanced 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/jinja-proposal.md`\n- **Seamless Support with Langsmith**（project_doc）：Explore how LangSmith enhances OpenAI clients with seamless LLM observability 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/langsmith.md`\n- **Mastering Python asyncio.gather and asyncio.as completed for LLM Processing**（project_doc）：Master Python asyncio.gather and asyncio.as completed for efficient concurrent LLM processing with Instructor. Learn async programming patterns, rate limiting, and performance optimization for AI applications. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/learn-async.md`\n- **Building an LLM-based Reranker for your RAG pipeline**（project_doc）：Learn how to use Instructor and Pydantic to create an LLM-based reranker for improving search results relevance. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/llm-as-reranker.md`\n- **Instructor Adopts llms.txt: Making Documentation AI-Friendly**（project_doc）：Instructor Adopts llms.txt: Making Documentation AI-Friendly 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/llms-txt-adoption.md`\n- **Instructor Now Supports llms.txt**（project_doc）：We've added automatic llms.txt generation to Instructor's documentation using the mkdocs-llmstxt https://github.com/pawamoy/mkdocs-llmstxt plugin. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/llms-txt-support.md`\n- **Introduction**（project_doc）：Explore Logfire, an observability platform to enhance application performance 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/logfire.md`\n- **London Stock Exchange Group Powers Market Surveillance with Instructor**（project_doc）：London Stock Exchange Group uses Instructor in production for AI-powered market surveillance, achieving 100% precision in detecting price-sensitive news 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/lseg-market-surveillance.md`\n- **Matching Language in Multilingual Summarization Tasks**（project_doc）：Explore techniques to ensure language models generate summaries that 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/matching-language.md`\n- **Why we migrated to uv**（project_doc）：How we migrated from poetry to uv 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/migrating-to-uv.md`\n- **Automating llms.txt Generation with mkdocs-llmstxt Plugin**（project_doc）：Automating llms.txt Generation with mkdocs-llmstxt Plugin 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/mkdocs-llmstxt-plugin-integration.md`\n- **Structured Outputs with Multimodal Gemini**（project_doc）：Learn how to use Google's Gemini model for multimodal structured extraction of YouTube videos, extracting structured recommendations for tourist destinations. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/multimodal-gemini.md`\n- **Native Caching in Instructor v1.9.1: Zero-Configuration Performance Boost**（project_doc）：Instructor v1.9.1 introduces native caching support for all providers. Learn how to drastically reduce API costs and improve response times with built-in cache adapters. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/native_caching.md`\n- **Structured Output for Open Source and Local LLMs**（project_doc）：Discover how Instructor integrates with OpenAI and local LLMs for structured 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/open_source.md`\n- **OpenAI API Model Distillation with Instructor**（project_doc）：Learn how to use OpenAI's API Model Distillation with Instructor to create 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/openai-distilation-store.md`\n- **Audio Support in OpenAI's Chat Completions API**（project_doc）：Explore the new audio capabilities in OpenAI's Chat Completions API using the gpt-4o-audio-preview model. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/openai-multimodal.md`\n- **Building a Pairwise LLM Judge with Instructor and Pydantic**（project_doc）：Explore how to use Instructor and Pydantic to create a pairwise LLM judge for evaluating text relevance. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/blog/posts/pairwise-llm-judge.md`\n\n## 证据索引\n\n- 共索引 79 条证据。\n\n- **Contributing to Instructor**（documentation）：We welcome contributions to Instructor! This page covers the different ways you can help improve the library. 证据：`docs/contributing.md`\n- **CLAUDE.md**（documentation）：This file provides guidance to Claude Code claude.ai/code when working with code in this repository. 证据：`CLAUDE.md`\n- **Instructor: Structured Outputs for LLMs**（documentation）：Instructor: Structured Outputs for LLMs 证据：`README.md`\n- **Scripts Directory**（documentation）：This directory contains utility scripts for maintaining and improving the Instructor documentation and project structure. 证据：`scripts/README.md`\n- **Cursor Rules**（documentation）：Cursor rules are configuration files that help guide AI-assisted development in the Cursor IDE. They provide structured instructions for how the AI should behave in specific contexts or when working with certain types of files. 证据：`.cursor/rules/readme.md`\n- **Batch API Examples**（documentation）：This directory contains examples and test scripts for Instructor's batch processing capabilities, including both traditional file-based and new in-memory processing. 证据：`examples/batch_api/README.md`\n- **Instructor Caching Prototype**（documentation）：This example demonstrates the new built-in caching functionality in Instructor. 证据：`examples/caching_prototype/README.md`\n- **Introduction**（documentation）：This is a simple example which shows how to perform Chain Of Density summarization using GPT-3.5 and utilise the generated output to fine-tune a 3.5 model for production usage. All of our data referenced in this file is located here https://huggingface.co/datasets/ivanleomk/gpt4-chain-of-density on hugging face 证据：`examples/chain-of-density/Readme.md`\n- **Citation with Extraction**（documentation）：This repository contains a FastAPI application that uses GPT-4 to answer questions based on a given context and extract relevant facts with correct and exact citations. The extracted facts are returned as JSON events using Server-Sent Events SSE . 证据：`examples/citation_with_extraction/README.md`\n- **FastAPI Code Generator**（documentation）：Generates FastAPI application code from API path, task name, JSON schema path, and Jinja2 prompt template. Also creates a models.py file for Pydantic models. 证据：`examples/codegen-from-schema/readme.md`\n- **What to Expect**（documentation）：What to Expect This script demonstrates how to use the Instructor library for fine-tuning a Python function that performs three-digit multiplication. It uses Pydantic for type validation and logging features to generate a fine-tuning dataset. 证据：`examples/distilations/readme.md`\n- **Instructor Hooks Example**（documentation）：This example demonstrates how to use the Hooks system in the Instructor library to monitor, log, and debug your LLM interactions. 证据：`examples/hooks/README.md`\n- **Instructions**（documentation）：1. Create a virtual environment and install all of the packages inside requirements.txt 证据：`examples/logfire-fastapi/Readme.md`\n- **Read first to correctly work with the provided examples**（documentation）：Read first to correctly work with the provided examples 证据：`examples/open_source_examples/README.md`\n- **Using llm validator with OpenAI's GPT-3.5 Turbo and Pydantic for Text Validation with Output Examples**（documentation）：Using llm validator with OpenAI's GPT-3.5 Turbo and Pydantic for Text Validation with Output Examples 证据：`examples/validators/readme.md`\n- **Providers Directory Structure**（documentation）：This directory contains implementations for all supported LLM providers in the instructor library. 证据：`instructor/providers/README.md`\n- **Contributing to Instructor**（documentation）：Thank you for considering contributing to Instructor! This document provides guidelines and instructions to help you contribute effectively. 证据：`CONTRIBUTING.md`\n- **Core Provider Tests**（documentation）：This directory contains unified tests that run across all core providers : OpenAI, Anthropic, Google Gemini , Cohere, xAI, Mistral, Cerebras, Fireworks, Writer, and Perplexity. 证据：`tests/llm/test_core_providers/README.md`\n- **License**（source_file）：Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files the \"Software\" , to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 证据：`LICENSE`\n- **AGENT.md - Documentation**（documentation）：Commands - Serve docs locally: uv run mkdocs serve - Build docs: ./build mkdocs.sh or uv run mkdocs build - Install doc deps: uv pip install -e \". docs \" - Test examples: uv run pytest docs/ --examples 证据：`docs/AGENT.md`\n- **API Docstring Quality Assessment**（documentation）：This document assesses the quality and completeness of docstrings for all API items referenced in the expanded API documentation. 证据：`docs/api-docstring-assessment.md`\n- **API Reference**（documentation）：Core modes are the recommended default. Legacy provider-specific modes still work but are deprecated and will show warnings. See the Mode Migration Guide concepts/mode-migration.md for details. 证据：`docs/api.md`\n- **Architecture Overview**（documentation）：This page explains the core execution flow and where to plug in or debug. It highlights the minimal sync/async code paths and how streaming, partial, and parallel modes integrate. 证据：`docs/architecture.md`\n- **Debugging**（documentation）：This guide shows how to quickly inspect inputs/outputs, capture retries, and reproduce failures when working with Instructor. It focuses on practical techniques using hooks, logging, and exception data. 证据：`docs/debugging.md`\n- **Frequently Asked Questions**（documentation）：This page answers common questions about using Instructor with various LLM providers. 证据：`docs/faq.md`\n- **Getting Started with Instructor**（documentation）：This guide will walk you through the basics of using Instructor to extract structured data from language models. By the end, you'll understand how to: 证据：`docs/getting-started.md`\n- **Getting help with Instructor**（documentation）：If you need help getting started with Instructor or with advanced usage, the following sources may be useful. 证据：`docs/help.md`\n- **Instructor: Top Multi-Language Library for Structured LLM Outputs**（documentation）：Instructor: Top Multi-Language Library for Structured LLM Outputs 证据：`docs/index.md`\n- **Installation**（documentation）：- openai https://pypi.org/project/openai/ : OpenAI's Python client. - typer https://pypi.org/project/typer/ : Build great CLIs. Easy to code. Based on Python type hints. - docstring-parser https://pypi.org/project/docstring-parser/ : A parser for Python docstrings, to improve the experience of working with docstrings in jsonschema. - pydantic https://pypi.org/project/pydantic/ : Data validation and settings management using python type annotations. 证据：`docs/installation.md`\n- **Instructor Mode Comparison Guide**（documentation）：Instructor uses core modes that work across providers. Provider-specific modes still work, but they are deprecated and will show warnings. 证据：`docs/modes-comparison.md`\n- **Instructor Newsletter**（documentation）：If you want to be notified of tips, new blog posts, and research, subscribe to our newsletter. Here's what you can expect: 证据：`docs/newsletter.md`\n- **Repository Overview**（documentation）：This page explains the layout of the Instructor codebase and what each key directory contains. 证据：`docs/repository-overview.md`\n- **Start Here: Instructor for Beginners**（documentation）：Start Here: Instructor for Beginners 证据：`docs/start-here.md`\n- **Why use Instructor?**（documentation）：You've built something with an LLM, but 15% of the time it returns garbage. Parsing JSON is a nightmare. Different providers have different APIs. There has to be a better way. 证据：`docs/why.md`\n- **Subscribe to our Newsletter for Updates and Tips**（documentation）：Subscribe to our Newsletter for Updates and Tips 证据：`docs/blog/index.md`\n- **AI Engineer Keynote: Pydantic is all you need**（documentation）：AI Engineer Keynote: Pydantic is all you need 证据：`docs/blog/posts/aisummit-2023.md`\n- **Structured Outputs for Gemini now supported**（documentation）：Structured Outputs for Gemini now supported 证据：`docs/blog/posts/announcing-gemini-tool-calling-support.md`\n- **Announcing Responses API support**（documentation）：We're excited to announce Instructor's integration with OpenAI's new Responses API. This integration brings a more streamlined approach to working with structured outputs from OpenAI models. Let's see what makes this integration special and how it can improve your LLM applications. 证据：`docs/blog/posts/announcing-instructor-responses-support.md`\n- **What is from provider ?**（documentation）：We are pleased to introduce a significant enhancement to Instructor: the from provider function. While Instructor has always focused on providing robust structured outputs, we've observed that many users work with multiple LLM providers. This often involves repetitive setup for each client. 证据：`docs/blog/posts/announcing-unified-provider-interface.md`\n- **Why should I use prompt caching?**（documentation）：Developers often face two key challenges when working with large context - Slow response times and high costs. This is especially true when we're making multiple of these calls over time, severely impacting the cost and latency of our applications. With Anthropic's new prompt caching feature, we can easily solve both of these issues. 证据：`docs/blog/posts/anthropic-prompt-caching.md`\n- **Using Anthropic's Web Search with Instructor for Real-Time Data**（documentation）：Using Anthropic's Web Search with Instructor for Real-Time Data 证据：`docs/blog/posts/anthropic-web-search-structured.md`\n- **Structured Outputs with Anthropic**（documentation）：A special shoutout to Shreya https://twitter.com/shreyaw for her contributions to the anthropic support. As of now, all features are operational with the exception of streaming support. 证据：`docs/blog/posts/anthropic.md`\n- **Bad Schemas could break your LLM Structured Outputs**（documentation）：Bad Schemas could break your LLM Structured Outputs 证据：`docs/blog/posts/bad-schemas-could-break-llms.md`\n- **Why Instructor is the Best Library for Structured LLM Outputs**（documentation）：Why Instructor is the Best Library for Structured LLM Outputs 证据：`docs/blog/posts/best_framework.md`\n- **Advanced Caching Strategies for Python LLM Applications Validated & Tested ✅**（documentation）：Advanced Caching Strategies for Python LLM Applications Validated & Tested ✅ 证据：`docs/blog/posts/caching.md`\n- **Smarter Summaries w/ Finetuning GPT-3.5 and Chain of Density**（documentation）：Smarter Summaries w/ Finetuning GPT-3.5 and Chain of Density 证据：`docs/blog/posts/chain-of-density.md`\n- **PDF Processing with Structured Outputs with Gemini**（documentation）：PDF Processing with Structured Outputs with Gemini 证据：`docs/blog/posts/chat-with-your-pdf-with-gemini.md`\n- **Verifying LLM Citations with Pydantic**（documentation）：Verifying LLM Citations with Pydantic 证据：`docs/blog/posts/citations.md`\n- **Consistent Stories with GPT-4o**（documentation）：Language Models struggle to generate consistent graphs that have a large number of nodes. Often times, this is because the graph itself is too large for the model to handle. This causes the model to generate inconsistent graphs that have invalid and disconnected nodes among other issues. 证据：`docs/blog/posts/consistent-stories.md`\n- **Free course on Weights and Biases**（documentation）：I just released a free course on wits and biases. It goes over the material from tutorial ../../tutorials/1-introduction.ipynb . Check it out at wandb.courses https://www.wandb.courses/courses/steering-language-models its free and open to everyone and just under an hour long! 证据：`docs/blog/posts/course.md`\n- **Instructor Adopting Cursor Rules**（documentation）：AI-assisted coding is changing how we use version control. Many developers now use what I call \"vibe coding\" - coding with AI help. This creates new challenges with Git. Today I'll share how we're using Cursor rules in Instructor to solve these problems. 证据：`docs/blog/posts/cursor-rules.md`\n- **Enhancing Python Functions with Instructor: A Guide to Fine-Tuning and Distillation**（documentation）：Enhancing Python Functions with Instructor: A Guide to Fine-Tuning and Distillation 证据：`docs/blog/posts/distilation-part1.md`\n- **Consistent Stories with GPT-4o**（documentation）：Language Models struggle to generate consistent graphs that have a large number of nodes. Often times, this is because the graph itself is too large for the model to handle. This causes the model to generate inconsistent graphs that have invalid and disconnected nodes among other issues. 证据：`docs/blog/posts/extract-model-looks.md`\n- **Why Image Metadata is useful**（documentation）：Multimodal Language Models like gpt-4o excel at processing multimodal, enabling us to extract rich, structured metadata from images. 证据：`docs/blog/posts/extracting-model-metadata.md`\n- **Simple Synthetic Data Generation**（documentation）：What that people have been using instructor for is to generate synthetic data rather than extracting data itself. We can even use the J-Schemo extra fields to give specific examples to control how we generate data. 证据：`docs/blog/posts/fake-data.md`\n- **Why Logfire is a perfect fit for FastAPI + Instructor**（documentation）：Why Logfire is a perfect fit for FastAPI + Instructor 证据：`docs/blog/posts/full-fastapi-visibility.md`\n- **Eliminating Hallucinations with Structured Outputs using Gemini**（documentation）：Eliminating Hallucinations with Structured Outputs using Gemini 证据：`docs/blog/posts/generating-pdf-citations.md`\n- **Generators and LLM Streaming**（documentation）：Latency is crucial, especially in eCommerce and newer chat applications like ChatGPT. Streaming is the solution that enables us to enhance the user experience without the need for faster response times. 证据：`docs/blog/posts/generator.md`\n- **Do I Still Need Instructor with Google's New OpenAI Integration?**（documentation）：Do I Still Need Instructor with Google's New OpenAI Integration? 证据：`docs/blog/posts/google-openai-client.md`\n- **Introducing structured outputs with Cerebras Inference**（documentation）：Introducing structured outputs with Cerebras Inference 证据：`docs/blog/posts/introducing-structured-outputs-with-cerebras-inference.md`\n- 其余 19 条证据见 `AI_CONTEXT_PACK.json` 或 `EVIDENCE_INDEX.json`。\n\n## 宿主 AI 必须遵守的规则\n\n- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`docs/contributing.md`, `CLAUDE.md`, `README.md`\n- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`docs/contributing.md`, `CLAUDE.md`, `README.md`\n\n## 用户开工前应该回答的问题\n\n- 你准备在哪个宿主 AI 或本地环境中使用它？\n- 你只是想先体验工作流，还是准备真实安装？\n- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？\n\n## 验收标准\n\n- 所有能力声明都能回指到 evidence_refs 中的文件路径。\n- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。\n- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。\n\n---\n\n## Doramagic Context Augmentation\n\n下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。\n\n## Human Manual 骨架\n\n使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。\n\n宿主 AI 硬性规则：\n- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。\n- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。\n- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。\n\n- **Introduction to Instructor**：importance `high`\n  - source_paths: README.md, instructor/__init__.py\n- **Getting Started with Instructor**：importance `high`\n  - source_paths: docs/getting-started.md, docs/learning/getting_started/first_extraction.md, examples/simple-extraction/user.py\n- **Installation and Setup**：importance `high`\n  - source_paths: docs/installation.md, pyproject.toml\n- **Project Structure**：importance `medium`\n  - source_paths: instructor/core/client.py, instructor/providers/README.md, instructor/processing/schema.py\n- **Core Components Architecture**：importance `high`\n  - source_paths: instructor/core/client.py, instructor/core/hooks.py, instructor/core/retry.py, instructor/process_response.py\n- **Response Models and Type Safety**：importance `high`\n  - source_paths: docs/concepts/models.md, docs/concepts/fields.md, docs/learning/getting_started/response_models.md, instructor/processing/schema.py\n- **Validation and Retry Mechanisms**：importance `high`\n  - source_paths: instructor/core/retry.py, instructor/validation/llm_validators.py, instructor/processing/validators.py, docs/concepts/retrying.md, docs/concepts/validation.md\n- **Streaming and Partial Responses**：importance `medium`\n  - source_paths: instructor/dsl/partial.py, instructor/dsl/iterable.py, docs/concepts/partial.md, docs/concepts/iterable.md, examples/partial_streaming/run.py\n\n## Repo Inspection Evidence / 源码检查证据\n\n- repo_clone_verified: true\n- repo_inspection_verified: true\n- repo_commit: `5e8e2d57e791ed505c9637c0e215b10a5441b66a`\n- inspected_files: `pyproject.toml`, `README.md`, `uv.lock`, `requirements.txt`, `docs/why.md`, `docs/architecture.md`, `docs/contributing.md`, `docs/newsletter.md`, `docs/debugging.md`, `docs/index.md`, `docs/api.md`, `docs/repository-overview.md`, `docs/getting-started.md`, `docs/api-docstring-assessment.md`, `docs/installation.md`, `docs/modes-comparison.md`, `docs/start-here.md`, `docs/faq.md`, `docs/help.md`, `docs/jobs.md`\n\n宿主 AI 硬性规则：\n- 没有 repo_clone_verified=true 时，不得声称已经读过源码。\n- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。\n- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。\n\n## Doramagic Pitfall Constraints / 踩坑约束\n\n这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。\n\n### Constraint 1: 来源证据：Documentation (at least Google-related) is an outdated mess.\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Documentation (at least Google-related) is an outdated mess.\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_b87b003416cd4308bc863f0cd66a68fd | https://github.com/567-labs/instructor/issues/2289 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 2: 来源证据：v1.13.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v1.13.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_f3c1e8416a744b51b5691317c10bc5bf | https://github.com/567-labs/instructor/releases/tag/v1.13.0 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 3: 来源证据：v1.12.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.12.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_9b8236f58f8641c586777618a838409f | https://github.com/567-labs/instructor/releases/tag/v1.12.0 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 4: 来源证据：v1.14.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_053ef3382ace48778d05ef006d87cead | https://github.com/567-labs/instructor/releases/tag/v1.14.0 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 5: 来源证据：v1.14.3\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.3\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能阻塞安装或首次运行。\n- Evidence: community_evidence:github | cevd_d18c003929614c7097d16742ec94cc8c | https://github.com/567-labs/instructor/releases/tag/v1.14.3 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 6: 来源证据：v1.14.4\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.4\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能阻塞安装或首次运行。\n- Evidence: community_evidence:github | cevd_76987134f9a747d685958a5e98f3b51a | https://github.com/567-labs/instructor/releases/tag/v1.14.4 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 7: 来源证据：v1.15.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.15.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_430369db61e440e5a4b575e2b3618464 | https://github.com/567-labs/instructor/releases/tag/v1.15.0 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 8: 能力判断依赖假设\n\n- Trigger: README/documentation is current enough for a first validation pass.\n- Host AI rule: 将假设转成下游验证清单。\n- Why it matters: 假设不成立时，用户拿不到承诺的能力。\n- Evidence: capability.assumptions | github_repo:653589102 | https://github.com/567-labs/instructor | README/documentation is current enough for a first validation pass.\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 9: 来源证据：v1.14.2\n\n- Trigger: GitHub 社区证据显示该项目存在一个运行相关的待验证问题：v1.14.2\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能阻塞安装或首次运行。\n- Evidence: community_evidence:github | cevd_fd561faf78f147518bcda7a0370a9a4f | https://github.com/567-labs/instructor/releases/tag/v1.14.2 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 10: 维护活跃度未知\n\n- Trigger: 未记录 last_activity_observed。\n- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Evidence: evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | last_activity_observed missing\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n",
      "summary": "给宿主 AI 的上下文和工作边界。",
      "title": "AI Context Pack / 带给我的 AI"
    },
    "boundary_risk_card": {
      "asset_id": "boundary_risk_card",
      "filename": "BOUNDARY_RISK_CARD.md",
      "markdown": "# Boundary & Risk Card / 安装前决策卡\n\n项目：567-labs/instructor\n\n## Doramagic 试用结论\n\n当前结论：可以进入发布前推荐检查；首次使用仍应从最小权限、临时目录和可回滚配置开始。\n\n## 用户现在可以做\n\n- 可以先阅读 Human Manual，理解项目目的和主要工作流。\n- 可以复制 Prompt Preview 做安装前体验；这只验证交互感，不代表真实运行。\n- 可以把官方 Quick Start 命令放到隔离环境中验证，不要直接进主力环境。\n\n## 现在不要做\n\n- 不要把 Prompt Preview 当成项目实际运行结果。\n- 不要把 metadata-only validation 当成沙箱安装验证。\n- 不要把未验证能力写成“已支持、已跑通、可放心安装”。\n- 不要在首次试用时交出生产数据、私人文件、真实密钥或主力配置目录。\n\n## 安装前检查\n\n- 宿主 AI 是否匹配：chatgpt\n- 官方安装入口状态：已发现官方入口\n- 是否在临时目录、临时宿主或容器中验证：必须是\n- 是否能回滚配置改动：必须能\n- 是否需要 API Key、网络访问、读写文件或修改宿主配置：未确认前按高风险处理\n- 是否记录了安装命令、实际输出和失败日志：必须记录\n\n## 当前阻塞项\n\n- 无阻塞项。\n\n## 项目专属踩坑\n\n- 来源证据：Documentation (at least Google-related) is an outdated mess.（high）：可能影响升级、迁移或版本选择。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：v1.13.0（medium）：可能影响升级、迁移或版本选择。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 来源证据：v1.12.0（medium）：可能影响升级、迁移或版本选择。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 来源证据：v1.14.0（medium）：可能增加新用户试用和生产接入成本。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 来源证据：v1.14.3（medium）：可能阻塞安装或首次运行。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n\n## 风险与权限提示\n\n- no_demo: medium\n\n## 证据缺口\n\n- 暂未发现结构化证据缺口。\n",
      "summary": "安装、权限、验证和推荐前风险。",
      "title": "Boundary & Risk Card / 边界与风险卡"
    },
    "human_manual": {
      "asset_id": "human_manual",
      "filename": "HUMAN_MANUAL.md",
      "markdown": "# https://github.com/567-labs/instructor 项目说明书\n\n生成时间：2026-05-16 03:25:27 UTC\n\n## 目录\n\n- [Introduction to Instructor](#introduction)\n- [Getting Started with Instructor](#getting-started)\n- [Installation and Setup](#installation)\n- [Project Structure](#project-structure)\n- [Core Components Architecture](#core-components)\n- [Response Models and Type Safety](#response-models)\n- [Validation and Retry Mechanisms](#validation-retries)\n- [Streaming and Partial Responses](#streaming)\n- [LLM Provider Support](#providers)\n- [Unified Provider Interface](#from-provider)\n\n<a id='introduction'></a>\n\n## Introduction to Instructor\n\n### 相关页面\n\n相关主题：[Getting Started with Instructor](#getting-started), [Installation and Setup](#installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [instructor/__init__.py](https://github.com/567-labs/instructor/blob/main/instructor/__init__.py) *(referenced but not directly included in context)*\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n</details>\n\n# Introduction to Instructor\n\nInstructor is an open-source Python library that simplifies structured output extraction from Large Language Models (LLMs). It provides a unified API across multiple LLM providers, enabling developers to define response models using Pydantic and automatically receive validated, typed outputs from AI responses.\n\n## Overview\n\nInstructor addresses a common challenge in LLM development: parsing and validating unstructured model outputs into structured data types. Traditional approaches require manual JSON parsing, custom validation logic, and provider-specific code. Instructor streamlines this by:\n\n- Integrating directly with existing LLM provider clients\n- Using Pydantic models for response schema definition\n- Automatically retrying failed validations\n- Supporting multiple providers through a unified interface\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Core Concepts\n\n### Response Model Pattern\n\nAt the heart of Instructor is the `response_model` parameter. Developers define a Pydantic `BaseModel` class that specifies the expected structure of the LLM response:\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Automatic Retries\n\nWhen validation fails (e.g., the LLM returns invalid data), Instructor automatically retries the request, passing the validation error back to the model for correction:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Supported Providers\n\nInstructor provides a unified API that works with multiple LLM providers. The `from_provider()` method creates a configured client for any supported provider.\n\n### Provider Support Matrix\n\n| Provider | Client Method | API Key Environment Variable |\n|----------|---------------|------------------------------|\n| OpenAI | `instructor.from_provider(\"openai/...\")` | `OPENAI_API_KEY` |\n| Anthropic | `instructor.from_provider(\"anthropic/...\")` | `ANTHROPIC_API_KEY` |\n| Google | `instructor.from_provider(\"google/...\")` | `GOOGLE_API_KEY` |\n| Ollama | `instructor.from_provider(\"ollama/...\")` | N/A (local) |\n| Groq | `instructor.from_provider(\"groq/...\")` | `GROQ_API_KEY` |\n\n### Supported Models by Provider\n\n**OpenAI Models:**\n- `openai/gpt-4o`\n- `openai/gpt-4o-mini`\n- `openai/gpt-4-turbo`\n\n**Anthropic Models:**\n- `anthropic/claude-3-5-sonnet-20241022`\n- `anthropic/claude-3-opus-20240229`\n- `anthropic/claude-3-haiku-20240307`\n\n**Google Models:**\n- `google/gemini-2.0-flash-001`\n- `google/gemini-pro`\n- `google/gemini-pro-vision`\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md), [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## Installation\n\n### Standard Installation\n\n```bash\npip install instructor\n```\n\n### Package Managers\n\n```bash\n# Using uv\nuv add instructor\n\n# Using poetry\npoetry add instructor\n```\n\n### API Key Configuration\n\nProviders can be configured using environment variables or passed directly:\n\n```python\n# From environment variables\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Direct API key\nclient = instructor.from_provider(\n    \"openai/gpt-4o\", \n    api_key=\"sk-...\"\n)\n\nclient = instructor.from_provider(\n    \"anthropic/claude-3-5-sonnet\",\n    api_key=\"sk-ant-...\"\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Advanced Features\n\n### Caching\n\nInstructor includes built-in caching mechanisms to reduce API calls and costs for repeated requests.\n\n**AutoCache (In-Memory LRU):**\n```python\nfrom instructor.cache import AutoCache\n\ncache = AutoCache(maxsize=100)\nclient = instructor.from_openai(OpenAI(), cache=cache)\n```\n\n**DiskCache (Persistent):**\n```python\nfrom instructor.cache import DiskCache\n\ncache = DiskCache(directory=\".instructor_cache\")\nclient = instructor.from_openai(OpenAI(), cache=cache)\n```\n\n**Cache TTL:**\n```python\nclient.create(\n    model=\"gpt-3.5-turbo\",\n    messages=messages,\n    response_model=User,\n    cache_ttl=3600,  # 1 hour\n)\n```\n\n**Performance Benefits:**\n- **156x faster** cache hits compared to API calls\n- **Identical results** from cache and API\n- **Persistent storage** across client instances\n- Cache invalidation based on prompts, models, schemas, and TTL\n\n资料来源：[examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n\n### Hooks System\n\nHooks allow developers to attach event handlers for monitoring and debugging LLM interactions.\n\n**Available Hook Events:**\n- Request details (model, prompt)\n- Input token count\n- Token usage statistics\n- Successful responses\n- Parse errors\n- Completion errors\n- Retry attempt notifications\n\n**Hook Types:**\n1. **On Request Hook**: Triggered before/after API requests\n2. **On Response Hook**: Triggered when responses are received\n3. **Parse Error Hook**: Handles JSON parsing failures\n4. **Completion Error Hook**: Handles API errors\n5. **Retry Hook**: Notifies on retry attempts\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### Batch Processing\n\nThe `BatchProcessor` provides a unified interface for creating batch jobs across providers.\n\n**Supported Operations:**\n```bash\n# Create batch from file\ninstructor batch create \\\n  --messages-file messages.jsonl \\\n  --model \"openai/gpt-4o-mini\" \\\n  --response-model \"examples.User\" \\\n  --output-file batch_requests.jsonl\n\n# Submit batch\ninstructor batch create-from-file \\\n  --file-path batch_requests.jsonl \\\n  --model \"openai/gpt-4o-mini\"\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Validation with LLM Validators\n\nBeyond standard Pydantic validators, Instructor supports `llm_validator` for complex validation scenarios:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Architecture\n\n### Provider Organization\n\nThe library organizes provider implementations in `instructor/providers/` with consistent patterns:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n**Provider Implementation Categories:**\n\n| Category | Providers |\n|----------|-----------|\n| Full Implementation (client.py + utils.py) | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai |\n| Client Only | genai, groq, vertexai |\n| Special (utils.py only) | openai |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Workflow Diagram\n\n```mermaid\ngraph TD\n    A[Define Pydantic Model] --> B[Create Instructor Client]\n    B --> C[Call create with response_model]\n    C --> D{Provider Selection}\n    D -->|OpenAI| E[OpenAI Handler]\n    D -->|Anthropic| F[Anthropic Handler]\n    D -->|Google| G[Google Handler]\n    E --> H[Parse Response]\n    F --> H\n    G --> H\n    H --> I{Validation Passed?}\n    I -->|Yes| J[Return Typed Object]\n    I -->|No| K[Retry with Error]\n    K --> C\n```\n\n## Example Applications\n\n### Citation Extraction\n\nInstructor powers applications that extract structured citations from documents:\n\n```bash\ncurl -X 'POST' \\\n  'https://jxnl--rag-citation-fastapi-app.modal.run/extract' \\\n  -H 'Authorization: Bearer <OPENAI_API_KEY>' \\\n  -d '{\n  \"context\": \"My name is Jason Liu...\",\n  \"query\": \"What did the author do in school?\"\n}'\n```\n\n**Response Format:**\n```json\n{\n  \"body\": \"In school, the author went to an arts high school.\",\n  \"spans\": [[91, 106]],\n  \"citation\": [\"arts highschool\"]\n}\n```\n\n资料来源：[examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n\n## Comparison: Without vs With Instructor\n\n| Aspect | Traditional Approach | With Instructor |\n|--------|----------------------|-----------------|\n| API Calls | Multiple calls for function definition | Single call |\n| Response Parsing | Manual JSON extraction | Automatic |\n| Validation | Custom error handling | Pydantic validation |\n| Retries | Manual implementation | Built-in automatic retries |\n| Provider Changes | Rewrite code | Same API across providers |\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Next Steps\n\n- Review the [official documentation](https://instructor-ai.github.io/instructor/) for detailed guides\n- Explore example implementations in the `examples/` directory\n- Contribute via GitHub issues and pull requests\n- Join the Instructor community for support and updates\n\n## License\n\nInstructor is released under the MIT License. See [LICENSE](https://github.com/567-labs/instructor/blob/main/LICENSE) for details.\n\n---\n\n<a id='getting-started'></a>\n\n## Getting Started with Instructor\n\n### 相关页面\n\n相关主题：[Installation and Setup](#installation), [Response Models and Type Safety](#response-models)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [scripts/README.md](https://github.com/567-labs/instructor/blob/main/scripts/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n</details>\n\n# Getting Started with Instructor\n\nInstructor is a Python library that simplifies structured data extraction from Large Language Model (LLM) responses. It integrates with multiple LLM providers and uses Pydantic for automatic validation, retry logic, and type safety. With Instructor, developers can define response models and receive fully validated, typed data directly from LLM outputs.\n\n资料来源：[README.md:1-50]()\n\n## Installation\n\nInstall Instructor using pip or your preferred package manager:\n\n```bash\npip install instructor\n```\n\nOr with alternative package managers:\n\n```bash\nuv add instructor\npoetry add instructor\n```\n\n资料来源：[README.md:51-60]()\n\n## Quick Start\n\nThe simplest way to use Instructor is with the `from_provider()` factory function:\n\n```python\nfrom pydantic import BaseModel\nimport instructor\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\n\n\nclass Product(BaseModel):\n    name: str\n    price: float\n    in_stock: bool\n\n\nproduct = client.chat.completions.create(\n    response_model=Product,\n    messages=[{\"role\": \"user\", \"content\": \"iPhone 15 Pro, $999, available now\"}],\n)\n\nprint(product)\n# Product(name='iPhone 15 Pro', price=999.0, in_stock=True)\n```\n\n资料来源：[README.md:125-150]()\n\n## Supported Providers\n\nInstructor works with multiple LLM providers using a unified API. The provider is automatically detected from the model identifier.\n\n### Provider Configuration Table\n\n| Provider | Model Identifier | API Key Parameter |\n|----------|------------------|-------------------|\n| OpenAI | `openai/gpt-4o-mini`, `openai/gpt-4o` | `api_key` |\n| Anthropic | `anthropic/claude-3-5-sonnet` | `api_key` |\n| Google | `google/gemini-pro` | `api_key` |\n| Ollama (local) | `ollama/llama3.2` | Local only |\n| Groq | `groq/llama-3.1-8b-instant` | `api_key` |\n\n### Usage Examples by Provider\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n\n# With explicit API keys\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n```\n\n资料来源：[README.md:61-90]()\n\n## Response Models\n\nResponse models define the expected output structure using Pydantic's `BaseModel`. Instructor automatically parses and validates LLM responses against these models.\n\n### Basic Model Definition\n\n```python\nfrom pydantic import BaseModel\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n### Without Instructor vs With Instructor\n\n```mermaid\ngraph TD\n    A[User Request] --> B[LLM API Call]\n    B --> C{Using Instructor?}\n    C -->|No| D[Raw JSON Response]\n    D --> E[Manual Parsing]\n    E --> F[Manual Validation]\n    F --> G[Handle Errors]\n    C -->|Yes| H[Response Model Defined]\n    H --> I[Automatic Parsing]\n    I --> J[Automatic Validation]\n    J --> K[Validated Output]\n```\n\n资料来源：[README.md:1-40]()\n\n## Validation\n\nInstructor provides automatic retry logic when validation fails. Define custom validators using Pydantic's `@field_validator` decorator.\n\n### Automatic Retries\n\n```python\nfrom pydantic import BaseModel, field_validator\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md:35-50]()\n\n### Custom LLM Validation\n\nUse `llm_validator` for content-based validation:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md:1-50]()\n\n## Hooks System\n\nHooks allow you to intercept and process requests and responses. The hooks system provides visibility into API calls.\n\n### Available Hook Events\n\n1. **Request Hook**: Triggered before sending a request to the LLM\n2. **Parse Error Hook**: Triggered when response parsing fails\n3. **Multiple Hooks**: Shows how to attach multiple handlers to the same event\n\n### Hook Usage Example\n\n```python\n# Hooks provide detailed information about each request:\n# - Request details (model, prompt)\n# - Approximate input token count\n# - Token usage statistics\n# - Successful responses\n# - Parse errors\n# - Completion errors\n# - Retry attempt notifications\n```\n\n资料来源：[examples/hooks/README.md:1-40]()\n\n## Advanced Features\n\n### Citation with Extraction\n\nExtract structured data with precise citations from source text:\n\n```python\n# FastAPI endpoint example\nresponse = client.chat.completions.create(\n    response_model=Facts,\n    messages=[...],\n)\n# Returns extracted facts with exact span positions and citations\n```\n\n资料来源：[examples/citation_with_extraction/README.md:1-80]()\n\n### Batch Processing\n\nProcess multiple requests efficiently using batch APIs:\n\n```bash\n# Test OpenAI\npython run_batch_test.py create --model \"openai/gpt-4o-mini\"\n\n# Test Anthropic\npython run_batch_test.py create --model \"anthropic/claude-3-5-sonnet-20241022\"\n```\n\n**Supported Batch Models Table**\n\n| Provider | Models |\n|----------|--------|\n| OpenAI | `gpt-4o-mini`, `gpt-4o`, `gpt-4-turbo` |\n| Anthropic | `claude-3-5-sonnet-20241022`, `claude-3-opus-20240229`, `claude-3-haiku-20240307` |\n| Google | `gemini-2.0-flash-001`, `gemini-pro`, `gemini-pro-vision` |\n\n资料来源：[examples/batch_api/README.md:1-70]()\n\n### Fine-Tuning and Distillation\n\nGenerate fine-tuning datasets from Instructor outputs:\n\n```bash\n# Run the script to generate training data\npython three_digit_mul.py\n\n# Create fine-tuning job\ninstructor jobs create-from-file math_finetunes.jsonl\n\n# With validation data\ninstructor jobs create-from-file math_finetunes.jsonl --n-epochs 4 --validation-file math_finetunes_val.jsonl\n```\n\n资料来源：[examples/distilations/readme.md:1-60]()\n\n## Provider Architecture\n\nEach provider is organized in its own subdirectory under `providers/`:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n### Provider Implementation Patterns\n\n| Pattern | Providers |\n|---------|-----------|\n| Both `client.py` and `utils.py` | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai |\n| Only `client.py` | genai, groq, vertexai |\n| Only `utils.py` (core) | OpenAI |\n\n资料来源：[instructor/providers/README.md:1-40]()\n\n## Utility Scripts\n\nThe repository includes maintenance scripts in the `scripts/` directory:\n\n| Script | Purpose |\n|--------|---------|\n| `make_clean.py` | Cleans markdown files, removes special whitespace characters |\n| `check_blog_excerpts.py` | Validates blog posts contain `<!-- more -->` tags |\n| `make_sitemap.py` | Generates sitemap with AI-powered content analysis |\n| `fix_api_calls.py` | Standardizes API call patterns |\n| `audit_patterns.py` | Audits documentation for outdated patterns |\n\n### Script Usage\n\n```bash\n# Clean markdown files\npython scripts/make_clean.py --dry-run\n\n# Check blog excerpts\npython scripts/check_blog_excerpts.py\n\n# Generate sitemap\npython scripts/make_sitemap.py\n\n# Audit documentation\npython scripts/audit_patterns.py --summary\n```\n\n资料来源：[scripts/README.md:1-100]()\n\n## Next Steps\n\n- Explore the [examples directory](https://github.com/567-labs/instructor/tree/main/examples) for complete working examples\n- Review the [validators documentation](examples/validators/readme.md) for advanced validation patterns\n- Learn about [hooks](examples/hooks/README.md) for request introspection\n- Set up [batch processing](examples/batch_api/README.md) for large-scale extractions\n- Consider [fine-tuning](examples/distilations/readme.md) for domain-specific tasks\n\n## Statistics and Community\n\nInstructor is trusted by over 100,000 developers and used in production by teams at OpenAI, Google, Microsoft, and AWS.\n\n| Metric | Value |\n|--------|-------|\n| Monthly Downloads | 3M+ |\n| GitHub Stars | 10K+ |\n| Contributors | 1000+ |\n\n资料来源：[README.md:95-110]()\n\n---\n\n<a id='installation'></a>\n\n## Installation and Setup\n\n### 相关页面\n\n相关主题：[Getting Started with Instructor](#getting-started), [LLM Provider Support](#providers)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/caching_prototype/README.md](https://github.com/567-labs/instructor/blob/main/examples/caching_prototype/README.md)\n- [examples/citation_with_extraction/README.md](https://github.com/567-labs/instructor/blob/main/examples/citation_with_extraction/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n</details>\n\n# Installation and Setup\n\n## Overview\n\nInstructor is a Python library that enables structured outputs from Large Language Models (LLMs) using type validation through Pydantic. It provides a unified API across multiple LLM providers, allowing developers to define response models and receive type-safe, validated responses automatically.\n\n资料来源：[README.md:1-50]()\n\n## System Requirements\n\n| Requirement | Specification |\n|------------|---------------|\n| Python Version | 3.9 or higher |\n| Package Manager | pip, uv, or poetry |\n| Optional Dependencies | OpenAI, Anthropic, Google SDKs based on provider selection |\n\n资料来源：[examples/distilations/readme.md:10-12]()\n\n## Installation Methods\n\n### Using pip\n\nThe simplest installation method uses pip:\n\n```bash\npip install instructor\n```\n\n资料来源：[README.md:60]()\n\n### Using uv\n\nFor projects using uv as the package manager:\n\n```bash\nuv add instructor\n```\n\n资料来源：[README.md:64]()\n\n### Using poetry\n\nFor projects using Poetry for dependency management:\n\n```bash\npoetry add instructor\n```\n\n资料来源：[README.md:65]()\n\n## Provider Setup\n\nInstructor supports multiple LLM providers with a unified interface. The following diagram illustrates the provider architecture:\n\n```mermaid\ngraph TD\n    A[Application Code] --> B[Instructor Client]\n    B --> C{Provider Type}\n    C -->|OpenAI| D[OpenAI Provider]\n    C -->|Anthropic| E[Anthropic Provider]\n    C -->|Google| F[Gemini Provider]\n    C -->|Ollama| G[Ollama Provider]\n    C -->|Groq| H[Groq Provider]\n    C -->|VertexAI| I[VertexAI Provider]\n    D --> J[Provider API]\n    E --> J\n    F --> J\n    G --> J\n    H --> J\n    I --> J\n```\n\n资料来源：[README.md:70-90]()\n\n### Basic Provider Initialization\n\nInitialize clients using the `from_provider()` factory function:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md:70-85]()\n\n### API Key Configuration\n\nAPI keys can be configured in two ways:\n\n| Method | Configuration |\n|--------|---------------|\n| Environment Variable | Set provider-specific env var (e.g., `OPENAI_API_KEY`) |\n| Direct Parameter | Pass `api_key` parameter to `from_provider()` |\n\n#### Direct API Key Configuration\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n\n# Groq\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\n资料来源：[README.md:85-92]()\n\n## Basic Usage Pattern\n\nThe fundamental usage pattern involves:\n\n1. Creating an instructor client\n2. Defining a Pydantic response model\n3. Calling the client with the response model\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md:45-55]()\n\n## Provider-Specific Initialization\n\nSome providers may require additional setup:\n\n### OpenAI Provider\n\nThe OpenAI provider is the reference implementation and uses `from_openai()` or `from_provider()`:\n\n```python\nimport instructor\nimport openai\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\n```\n\n资料来源：[README.md:70-72]()\n\n### Anthropic Provider\n\nRequires the `ANTHROPIC_API_KEY` environment variable:\n\n```bash\nexport ANTHROPIC_API_KEY=\"your-anthropic-api-key\"\n```\n\n资料来源：[examples/batch_api/README.md:45-50]()\n\n### Google Provider\n\nFor Gemini models, ensure the Google SDK is installed and `GOOGLE_API_KEY` is set:\n\n```bash\npip install google-generativeai\n```\n\n资料来源：[examples/batch_api/README.md:55-60]()\n\n## Optional Dependencies\n\nDepending on your use case, you may need additional dependencies:\n\n### For Caching Features\n\n```python\nfrom instructor.cache import AutoCache, DiskCache\n```\n\n资料来源：[examples/caching_prototype/README.md:12-15]()\n\n### For Validation\n\n```python\nfrom instructor import llm_validator, patch\n```\n\n资料来源：[examples/validators/readme.md:15-17]()\n\n### For Sitemap Generation (Documentation Scripts)\n\n```bash\nuv add openai typer rich tenacity pyyaml\n```\n\n资料来源：[scripts/README.md:85-87]()\n\n## Supported Models by Provider\n\n| Provider | Models |\n|----------|--------|\n| OpenAI | gpt-4o-mini, gpt-4o, gpt-4-turbo |\n| Anthropic | claude-3-5-sonnet-20241022, claude-3-opus-20240229, claude-3-haiku-20240307 |\n| Google | gemini-2.0-flash-001, gemini-pro, gemini-pro-vision |\n| Ollama | llama3.2, and other local models |\n\n资料来源：[examples/batch_api/README.md:25-35]()\n\n## Verification Installation\n\nTo verify your installation, create a simple test:\n\n```python\nimport instructor\nfrom pydantic import BaseModel\n\nclass TestModel(BaseModel):\n    result: str\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\nresult = client.chat.completions.create(\n    model=\"gpt-4o-mini\",\n    response_model=TestModel,\n    messages=[{\"role\": \"user\", \"content\": \"Say 'Hello, World!'\"}],\n)\nprint(result.result)  # Should print: Hello, World!\n```\n\n## Common Setup Issues\n\n| Issue | Solution |\n|-------|----------|\n| API key not found | Set the appropriate environment variable or pass `api_key` parameter |\n| Invalid model format | Use format `provider/model-name`, e.g., `openai/gpt-4o-mini` |\n| Unsupported provider | Use `openai`, `anthropic`, `google`, `ollama`, or `groq` |\n\n资料来源：[examples/batch_api/README.md:65-75]()\n\n## Next Steps\n\nAfter installation, consider exploring:\n\n- **Response Models**: Define Pydantic models for structured outputs\n- **Validation**: Add custom validators to response models\n- **Retries**: Instructor automatically retries failed validations\n- **Hooks**: Add logging and monitoring to requests\n\n资料来源：[README.md:95-115]()\n\n## Provider Architecture Details\n\nThe providers directory follows a consistent structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\nNot all providers require both files. Simpler providers like `genai`, `groq`, and `vertexai` use only `client.py`, while more complex ones like `anthropic`, `bedrock`, and `gemini` include both files.\n\n资料来源：[providers/README.md:1-25]()\n\n## Adding New Providers\n\nTo add support for a new LLM provider:\n\n1. Create a new subdirectory under `providers/`\n2. Add an `__init__.py` file\n3. Implement the `from_<provider>()` factory function\n4. Add provider-specific utilities as needed\n\n资料来源：[providers/README.md:27-32]()\n\n---\n\n<a id='project-structure'></a>\n\n## Project Structure\n\n### 相关页面\n\n相关主题：[Core Components Architecture](#core-components), [LLM Provider Support](#providers)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# Project Structure\n\n## Overview\n\nInstructor is a Python library that enables structured outputs from Large Language Models (LLMs) using Pydantic models for type validation. The project is organized into a modular architecture that separates core functionality, provider implementations, and example applications.\n\nThe primary goal of Instructor's project structure is to provide a unified API that works across multiple LLM providers while maintaining clean separation of concerns between client logic, provider-specific implementations, and response processing.\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    A[User Code] --> B[Core Client API]\n    B --> C[Provider Detection]\n    C --> D{Provider Type}\n    D -->|OpenAI| E[OpenAI Utils]\n    D -->|Anthropic| F[Anthropic Client]\n    D -->|Google| G[Gemini Utils]\n    D -->|Other| H[Provider-specific]\n    E --> I[Response Processing]\n    F --> I\n    G --> I\n    H --> I\n    I --> J[Pydantic Validation]\n    J --> K[Typed Response Model]\n```\n\n资料来源：[instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n\n## Directory Structure\n\n```\ninstructor/\n├── core/                    # Core client and base functionality\n│   ├── client.py           # Main client implementation\n│   └── ...\n├── providers/              # Provider-specific implementations\n│   ├── anthropic/          # Anthropic Claude integration\n│   ├── bedrock/            # AWS Bedrock integration\n│   ├── cerebras/           # Cerebras integration\n│   ├── cohere/             # Cohere integration\n│   ├── fireworks/          # Fireworks AI integration\n│   ├── gemini/             # Google Gemini integration\n│   ├── genai/              # Google Generative AI\n│   ├── groq/               # Groq integration\n│   ├── mistral/            # Mistral AI integration\n│   ├── perplexity/         # Perplexity AI integration\n│   ├── vertexai/           # Google Vertex AI integration\n│   ├── writer/             # Writer AI integration\n│   ├── xai/                 # xAI integration\n│   └── README.md           # Provider documentation\n├── processing/             # Response processing and validation\n│   ├── schema.py           # Schema handling\n│   └── ...\n├── cli/                    # Command-line interface\n│   └── ...\n└── ...\n\nexamples/\n├── batch_api/              # Batch processing examples\n├── citation_with_extraction/ # Extraction examples\n├── distilations/           # Fine-tuning examples\n├── hooks/                  # Hook system examples\n└── validators/             # Validation examples\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Core Components\n\n### Core Client Module\n\nThe core client module (`instructor/core/client.py`) provides the unified API for all LLM providers. It handles:\n\n| Component | Purpose |\n|-----------|---------|\n| `from_provider()` | Factory function to create provider-specific clients |\n| `client.create()` | Unified method for structured completions |\n| `client.create_partial()` | Streaming partial responses |\n| `client.create_iterable()` | Iterable response handling |\n| `client.create_with_completion()` | Responses with completion metadata |\n\n资料来源：[instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n\n### Basic Usage Pattern\n\n```python\n# Create client from any supported provider\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Use unified API for structured outputs\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Provider System\n\n### Provider Organization\n\nEach provider follows a consistent directory structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py    # Module exports\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Categories\n\n| Category | Providers | Files |\n|----------|-----------|-------|\n| Full Implementation | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai | `client.py` + `utils.py` |\n| Simplified | genai, groq, vertexai | `client.py` only |\n| Reference | openai | `utils.py` only (core handles `from_openai()`) |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Supported Providers\n\n```mermaid\ngraph LR\n    A[Instructor] --> B[OpenAI]\n    A --> C[Anthropic]\n    A --> D[Google]\n    A --> E[Groq]\n    A --> F[Vertex AI]\n    A --> G[Mistral]\n    A --> H[ Cohere]\n    A --> I[Fireworks]\n    A --> J[Cerebras]\n    A --> K[Perplexity]\n    A --> L[Writer]\n    A --> M[xAI]\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Processing Module\n\nThe processing module (`instructor/processing/`) handles response parsing and validation:\n\n| Component | Purpose |\n|-----------|---------|\n| Schema Handler | Transforms Pydantic models into LLM-compatible schemas |\n| Response Parser | Extracts structured data from LLM responses |\n| Validation Engine | Validates responses against Pydantic models |\n\n资料来源：[instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n\n## Example Applications\n\nThe `examples/` directory contains functional demonstrations:\n\n| Example | Purpose |\n|---------|---------|\n| `batch_api/` | Batch processing with multiple providers |\n| `citation_with_extraction/` | Fact extraction with citations |\n| `distilations/` | Model fine-tuning with Instructor |\n| `hooks/` | Event hook system for monitoring |\n| `validators/` | Custom validation with `llm_validator` |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Batch Processing Architecture\n\n```mermaid\ngraph TD\n    A[User Messages] --> B[BatchProcessor]\n    B --> C[Provider Detection]\n    C --> D{Provider}\n    D -->|OpenAI| E[batch.jsonl]\n    D -->|Anthropic| F[beta.messages.batches]\n    D -->|Google| G[GCS Simulation]\n    E --> H[Batch Submission]\n    F --> H\n    G --> H\n    H --> I[Batch ID Storage]\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Hooks System\n\nThe hooks system enables monitoring and logging of API operations:\n\n```python\n# Hook event types\n- on_request: Triggered before API call\n- on_response: Triggered after successful response\n- on_retry: Triggered during retry attempts\n- on_error: Triggered on validation/parse errors\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### Validation Examples\n\nCustom validation is achieved using Pydantic validators:\n\n```python\nfrom instructor import llm_validator, patch\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## CLI Tools\n\nThe project includes a command-line interface for common operations:\n\n```bash\n# Batch processing\ninstructor batch create --messages-file messages.jsonl --model \"openai/gpt-4o-mini\"\n\n# Fine-tuning job creation\ninstructor jobs create-from-file math_finetunes.jsonl\n```\n\n资料来源：[examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n\n## Installation and Dependencies\n\nThe project supports multiple package managers:\n\n```bash\n# pip\npip install instructor\n\n# uv\nuv add instructor\n\n# poetry\npoetry add instructor\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Scripts and Maintenance\n\nThe `scripts/` directory contains maintenance utilities:\n\n| Script | Purpose |\n|--------|---------|\n| `make_clean.py` | Clean markdown whitespace and dashes |\n| `make_sitemap.py` | Generate documentation sitemap |\n| `fix_api_calls.py` | Standardize API call patterns |\n| `fix_old_patterns.py` | Update deprecated patterns |\n| `audit_patterns.py` | Find outdated patterns in docs |\n\n资料来源：[scripts/README.md](https://github.com/567-labs/instructor/blob/main/scripts/README.md)\n\n## Key Design Patterns\n\n### Unified API Pattern\n\nInstructor provides a consistent interface across all providers:\n\n```python\n# Same code works for any provider\nclient = instructor.from_provider(\"provider/model-name\")\nresult = client.chat.completions.create(\n    response_model=YourModel,\n    messages=[...]\n)\n```\n\n### Factory Pattern\n\nThe `from_provider()` factory function creates appropriate clients based on the provider string:\n\n```python\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\nclient = instructor.from_provider(\"google/gemini-pro\")\n```\n\n### Validation Pipeline\n\n```mermaid\ngraph LR\n    A[LLM Response] --> B[Parse Tool Call]\n    B --> C[Extract Arguments]\n    C --> D[JSON Deserialization]\n    D --> E[Pydantic Validation]\n    E -->|Success| F[Typed Response]\n    E -->|Failure| G[Retry with Error]\n    G --> A\n```\n\n## Version Compatibility Notes\n\n- OpenAI uses a specialized `utils.py` without a `client.py` because `from_openai()` is defined in the core client\n- This is because OpenAI serves as the reference implementation for the library\n- OpenAI utilities are still required by core processing logic for standard handling\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n---\n\n<a id='core-components'></a>\n\n## Core Components Architecture\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>Relevant Source Files</summary>\n\nThe following source files are referenced for this page:\n\n- [instructor/core/client.py](https://github.com/567-labs/instructor/blob/main/instructor/core/client.py)\n- [instructor/core/hooks.py](https://github.com/567-labs/instructor/blob/main/instructor/core/hooks.py)\n- [instructor/core/retry.py](https://github.com/567-labs/instructor/blob/main/instructor/core/retry.py)\n- [instructor/process_response.py](https://github.com/567-labs/instructor/blob/main/instructor/process_response.py)\n</details>\n\n# Core Components Architecture\n\n## Overview\n\nThe Instructor library is built on a modular architecture that enables structured LLM outputs with automatic validation and retry capabilities. The core components work together to provide a unified API across multiple LLM providers while maintaining extensibility through hooks and a robust retry mechanism.\n\n```mermaid\ngraph TD\n    A[User Code] --> B[Instructor Client]\n    B --> C[Provider Adapter]\n    C --> D[LLM API]\n    D --> E[Response]\n    E --> F[Response Processor]\n    F --> G[Validation]\n    G -->|Success| H[Typed Response]\n    G -->|Failure| I[Retry Logic]\n    I -->|Retry| D\n    I -->|Max Retries| J[Error]\n    F --> K[Hooks System]\n    K -->|On Response| B\n    K -->|On Validation Error| B\n```\n\n## Architecture Components\n\n### 1. Client Module (`instructor/core/client.py`)\n\nThe client module serves as the primary entry point for the Instructor library. It provides factory functions for creating provider-specific clients and implements the unified API interface.\n\n#### Key Responsibilities\n\n| Responsibility | Description |\n|---------------|-------------|\n| Client Factory | Creates provider-specific clients via `from_provider()` |\n| API Unification | Provides consistent interface across all LLM providers |\n| Method Dispatch | Routes `create()`, `create_partial()`, `create_iterable()` calls |\n| Response Model Handling | Passes response models to the processing pipeline |\n\n#### Supported Providers\n\nThe client architecture supports multiple providers through a consistent interface:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n\n# Groq\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\")\n```\n\n#### Core Client Interface\n\nThe unified client provides these primary methods:\n\n| Method | Purpose |\n|--------|---------|\n| `create()` | Standard response generation with full validation |\n| `create_partial()` | Streaming partial responses for progressive validation |\n| `create_iterable()` | Iterative generation for list/collection outputs |\n| `create_with_completion()` | Returns both the parsed response and completion details |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### 2. Hooks System (`instructor/core/hooks.py`)\n\nThe hooks system provides event-driven extensibility, allowing developers to intercept and respond to various stages of the LLM interaction lifecycle.\n\n#### Available Hook Events\n\n| Hook Event | Trigger | Common Use Cases |\n|------------|---------|------------------|\n| `on_request` | Before sending request to LLM | Logging, token counting |\n| `on_response` | After receiving response | Metrics collection |\n| `on_retry` | Before retry attempt | Retry count logging |\n| `on_validation_error` | When validation fails | Custom error handling |\n| `on_parse_error` | When response parsing fails | Debugging, fallback logic |\n\n#### Hook Handler Structure\n\n```mermaid\ngraph LR\n    A[LLM Request] --> B[on_request Hooks]\n    B --> C[API Call]\n    C --> D[on_response Hooks]\n    D --> E{Validation}\n    E -->|Pass| F[on_success Hooks]\n    E -->|Fail| G[on_validation_error Hooks]\n    F --> H[Return Response]\n    G --> I[Retry Logic]\n    I --> J[on_retry Hooks]\n```\n\n#### Hook Implementation Pattern\n\n```python\nfrom instructor.hooks import Hooks, HookEvent\n\nclass LoggingHooks(Hooks):\n    def on_request(self, request, **kwargs):\n        print(f\"🔍 Request: {request}\")\n        \n    def on_response(self, response, **kwargs):\n        print(f\"✅ Response received\")\n\n# Attach hooks to client\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient.attach_hooks(LoggingHooks())\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n### 3. Retry Mechanism (`instructor/core/retry.py`)\n\nThe retry module handles automatic retries when validation fails, implementing exponential backoff and maximum retry limits.\n\n#### Retry Configuration\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `max_retries` | 3 | Maximum number of retry attempts |\n| `initial_delay` | 1.0 | Initial delay between retries (seconds) |\n| `backoff_factor` | 2.0 | Multiplier for delay on each retry |\n| `max_delay` | 60.0 | Maximum delay between retries (seconds) |\n\n#### Retry Flow\n\n```mermaid\ngraph TD\n    A[Initial Call] --> B{Validation Pass?}\n    B -->|Yes| C[Return Response]\n    B -->|No| D{Retry Count < Max?}\n    D -->|Yes| E[Apply Backoff]\n    E --> F[Log Error]\n    F --> A\n    D -->|No| G[Raise Exception]\n```\n\n#### Custom Retry with Field Validators\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### 4. Response Processing (`instructor/process_response.py`)\n\nThe response processing module handles parsing LLM outputs into structured Pydantic models, including text parsing, JSON extraction, and model validation.\n\n#### Processing Pipeline\n\n| Stage | Component | Function |\n|-------|-----------|----------|\n| 1 | Raw Response | Receive response from LLM provider |\n| 2 | Content Extraction | Extract text content from provider-specific format |\n| 3 | JSON Parsing | Parse JSON from text content |\n| 4 | Model Instantiation | Create Pydantic model instance |\n| 5 | Validation | Run Pydantic validators |\n| 6 | Error Handling | Trigger retries or raise exceptions |\n\n#### Validation Error Handling\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BaseModel, BeforeValidator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n\ntry:\n    qa: QuestionAnswerNoEvil = client.chat.completions.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[...],\n    )\nexcept Exception as e:\n    print(e)  # Handles validation errors\n```\n\n#### LLM-Based Validation\n\nThe response processor supports `llm_validator` for semantic validation beyond Pydantic type checking:\n\n```python\nfrom instructor import llm_validator\n\nclass OutputModel(BaseModel):\n    reasoning: Annotated[str, BeforeValidator(llm_validator(\"be logical\"))]\n    answer: Annotated[str, BeforeValidator(llm_validator(\"be concise\"))]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Provider Architecture\n\n### Provider Organization\n\nThe `providers/` directory follows a consistent structure across all supported providers:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory\n│   └── utils.py       # Provider-specific utilities\n```\n\n#### Provider Categories\n\n| Category | Providers | Characteristics |\n|----------|-----------|-----------------|\n| Full Implementation | anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai | Custom client.py + utils.py |\n| Simplified | genai, groq, vertexai | client.py only |\n| Reference | openai | utils.py only (core implementation) |\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Detection\n\nThe unified client automatically detects the provider from the model string format:\n\n```python\n# Format: provider/model-name\nclient = instructor.from_provider(\"openai/gpt-4o\")\n#   - Provider: openai\n#   - Model: gpt-4o\n\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n#   - Provider: anthropic\n#   - Model: claude-3-5-sonnet\n```\n\n## Data Flow Diagram\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant Client\n    participant Provider\n    participant Processor\n    participant Validator\n    participant Hooks\n\n    User->>Client: create(response_model, messages)\n    Client->>Hooks: on_request\n    Client->>Provider: API Call\n    Provider->>Client: Raw Response\n    Client->>Processor: Parse Response\n    Processor->>Validator: Validate Model\n    Validator-->>Processor: Valid/Invalid\n    alt Valid\n        Processor->>Client: Parsed Response\n        Client->>Hooks: on_response\n        Client-->>User: Typed Response\n    else Invalid\n        Processor->>Hooks: on_validation_error\n        Client->>Hooks: on_retry\n        Client->>Provider: Retry API Call\n        Note over Client: Loop until max_retries\n    end\n```\n\n## Configuration Options\n\n### Client Configuration\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `response_model` | Pydantic Model | Required | The expected response structure |\n| `max_retries` | int | 3 | Maximum validation retry attempts |\n| `validation_context` | dict | None | Additional context for validators |\n| `max_tokens` | int | Provider default | Maximum output tokens |\n| `temperature` | float | Provider default | Sampling temperature |\n\n### Provider-Specific Configuration\n\n```python\n# With API keys directly\nclient = instructor.from_provider(\n    \"openai/gpt-4o\", \n    api_key=\"sk-...\"\n)\n\nclient = instructor.from_provider(\n    \"anthropic/claude-3-5-sonnet\", \n    api_key=\"sk-ant-...\"\n)\n\n# With custom settings\nclient = instructor.from_provider(\n    \"openai/gpt-4o\",\n    api_key=\"sk-...\",\n    max_retries=5,\n    timeout=30.0\n)\n```\n\n## Key Design Patterns\n\n### 1. Factory Pattern\n\nThe `from_provider()` factory method creates appropriate client instances based on the provider string:\n\n```python\ndef from_provider(provider: str, **kwargs) -> Instructor:\n    \"\"\"Factory function to create provider-specific client.\"\"\"\n```\n\n### 2. Adapter Pattern\n\nEach provider implements a consistent interface while handling provider-specific nuances:\n\n```mermaid\ngraph TD\n    A[Instructor API] --> B[Provider Adapter]\n    B --> C[OpenAI Adapter]\n    B --> D[Anthropic Adapter]\n    B --> E[Google Adapter]\n    B --> F[Other Providers]\n```\n\n### 3. Decorator Pattern\n\nHooks provide a way to extend functionality without modifying core classes:\n\n```python\n@hooks.on_response\ndef log_response(response):\n    # Logging functionality\n    pass\n```\n\n## Error Handling\n\n### Error Types\n\n| Error Type | Cause | Recovery Action |\n|------------|-------|------------------|\n| `ValidationError` | Pydantic validation fails | Automatic retry with error message |\n| `ParseError` | JSON parsing fails | Automatic retry |\n| `MaxRetriesExceeded` | All retries exhausted | Raise exception to user |\n| `APIError` | Provider API failure | Retry with backoff |\n\n### Exception Flow\n\n```mermaid\ngraph TD\n    A[API Call] --> B{Success?}\n    B -->|No| C[API Error]\n    C --> D{Retry < Max?}\n    D -->|Yes| E[Backoff]\n    E --> A\n    D -->|No| F[Raise APIError]\n    B -->|Yes| G[Parse Response]\n    G --> H{Parse Success?}\n    H -->|No| I[Parse Error]\n    I --> D\n    H -->|Yes| J[Validate Model]\n    J --> K{Valid?}\n    K -->|Yes| L[Return Result]\n    K -->|No| M[Validation Error]\n    M --> D\n```\n\n## Summary\n\nThe Core Components Architecture of Instructor provides:\n\n1. **Unified Client Interface** - Single API across all LLM providers\n2. **Automatic Validation** - Pydantic-based response validation\n3. **Smart Retries** - Automatic retry with exponential backoff\n4. **Extensible Hooks** - Event-driven customization\n5. **Provider Abstraction** - Consistent patterns across providers\n\nThis architecture enables developers to focus on application logic while Instructor handles the complexities of structured LLM outputs, validation, and error recovery.\n\n---\n\n<a id='response-models'></a>\n\n## Response Models and Type Safety\n\n### 相关页面\n\n相关主题：[Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [docs/concepts/models.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/models.md)\n- [docs/concepts/fields.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/fields.md)\n- [docs/learning/getting_started/response_models.md](https://github.com/567-labs/instructor/blob/main/docs/learning/getting_started/response_models.md)\n- [instructor/processing/schema.py](https://github.com/567-labs/instructor/blob/main/instructor/processing/schema.py)\n</details>\n\n# Response Models and Type Safety\n\n## Overview\n\nInstructor provides robust **Response Models** and **Type Safety** mechanisms that enable structured, validated outputs from Large Language Models. By leveraging Pydantic's validation system, Instructor ensures that LLM responses conform to expected schemas while automatically retrying failed validations.\n\n## What are Response Models?\n\nResponse Models are Pydantic `BaseModel` classes that define the expected structure and types of LLM outputs. They serve as a contract between your application and the LLM, ensuring type-safe, validated responses.\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Core Architecture\n\n```mermaid\ngraph TD\n    A[LLM API Call] --> B[Instructor Client]\n    B --> C[Response Model Definition]\n    C --> D[Pydantic Schema Validation]\n    D --> E{Validation Pass?}\n    E -->|Yes| F[Return Validated Object]\n    E -->|No| G[Extract Error Message]\n    G --> H[Retry with Error Context]\n    H --> B\n```\n\n## Using Response Models\n\n### Basic Usage\n\n```python\nfrom instructor import from_provider\nfrom pydantic import BaseModel\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"Extract: Jason is 28 years old\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Nested Response Models\n\nResponse Models support nested structures for complex data:\n\n```python\nclass Address(BaseModel):\n    street: str\n    city: str\n    country: str\n\nclass UserProfile(BaseModel):\n    name: str\n    age: int\n    address: Address\n```\n\n## Field Validators\n\nPydantic's `@field_validator` decorator enables custom validation logic for model fields.\n\n### Basic Validation\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Validation with Regex\n\n```python\nfrom pydantic import field_validator\n\nclass EmailModel(BaseModel):\n    email: str\n\n    @field_validator('email')\n    def validate_email_format(cls, v):\n        if '@' not in v:\n            raise ValueError('Invalid email format')\n        return v.lower()\n```\n\n## LLM Validators\n\nInstructor provides `llm_validator` for content-based validation using the LLM itself.\n\n### Setup\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BaseModel, BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n### Validation Workflow\n\n```mermaid\ngraph TD\n    A[LLM Generates Response] --> B[Apply BeforeValidator]\n    B --> C[LLM Validator Check]\n    C --> D{Validation Pass?}\n    D -->|Yes| E[Accept Response]\n    D -->|No| F[Raise Assertion Error]\n    F --> G[Retry with Context]\n```\n\n## Automatic Retries\n\nWhen validation fails, Instructor automatically retries the request with the error message included.\n\n### Retry Configuration\n\n```python\nqa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n    model=\"gpt-3.5-turbo\",\n    response_model=QuestionAnswerNoEvil,\n    max_retries=2,  # Number of retry attempts\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": \"You are a system that answers questions based on the context.\",\n        },\n        {\n            \"role\": \"user\",\n            \"content\": f\"using the context: {context}\\n\\nAnswer the following question: {question}\",\n        },\n    ],\n)\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n### Retry Behavior\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `max_retries` | `int` | `1` | Maximum number of retry attempts on validation failure |\n| `allow_override` | `bool` | `False` | Allows LLM to override validation with special flag |\n\n## Error Handling\n\n### Catching Validation Errors\n\n```python\ntry:\n    qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[\n            {\"role\": \"system\", \"content\": \"Answer questions based on context.\"},\n            {\"role\": \"user\", \"content\": f\"context: {context}\\nQuestion: {question}\"},\n        ],\n    )\nexcept Exception as e:\n    print(f\"Validation failed: {e}\")\n```\n\n### Error Output Example\n\n```\n1 validation error for QuestionAnswerNoEvil\nanswer\n    Assertion failed, The statement promotes sin and debauchery, which is objectionable.\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Supported Data Types\n\n| Type | Description | Example |\n|------|-------------|---------|\n| `str` | String text | `name: str` |\n| `int` | Integer numbers | `age: int` |\n| `float` | Decimal numbers | `price: float` |\n| `bool` | Boolean values | `is_active: bool` |\n| `list[T]` | Lists of type T | `tags: list[str]` |\n| `dict` | Dictionary objects | `metadata: dict` |\n| `enum` | Enumeration values | `status: Status` |\n| `Optional[T]` | Nullable values | `nickname: Optional[str]` |\n\n## Complete Example: User Extraction\n\n```python\nfrom instructor import from_provider\nfrom pydantic import BaseModel, field_validator\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n\n    @field_validator('email')\n    def validate_email(cls, v):\n        if '@' not in v:\n            raise ValueError('Invalid email address')\n        return v.lower()\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0 or v > 150:\n            raise ValueError('Age must be between 0 and 150')\n        return v\n\n# Automatic validation and retries\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"John is 35 years old, email: John@Example.com\"}],\n)\n\nprint(f\"Name: {user.name}\")      # John\nprint(f\"Age: {user.age}\")        # 35\nprint(f\"Email: {user.email}\")    # john@example.com\n```\n\n## Best Practices\n\n1. **Define clear schemas**: Use descriptive field names and type hints\n2. **Add validators early**: Catch invalid data at the source\n3. **Set appropriate retry limits**: Balance between reliability and cost\n4. **Use `allow_override` wisely**: Only when LLM feedback is acceptable\n5. **Handle exceptions**: Always wrap calls in try/except for production code\n\n## Related Concepts\n\n- [Fields Documentation](https://github.com/567-labs/instructor/blob/main/docs/concepts/fields.md) - Advanced field configuration\n- [Hooks System](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md) - Request/response lifecycle hooks\n- [Validations Examples](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md) - Custom validation patterns\n\n---\n\n<a id='validation-retries'></a>\n\n## Validation and Retry Mechanisms\n\n### 相关页面\n\n相关主题：[Response Models and Type Safety](#response-models), [Streaming and Partial Responses](#streaming)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# Validation and Retry Mechanisms\n\n## Overview\n\nInstructor provides robust validation and automatic retry mechanisms that work seamlessly with Pydantic models to ensure LLM outputs conform to expected schemas. When an LLM generates a response that fails validation, Instructor automatically retries the request with the validation error message included, allowing the model to self-correct its output.\n\nThe validation system extends beyond traditional Pydantic validators to include **LLM-based validators** that can check semantic content, tone, safety, and other qualitative aspects of generated text. Combined with automatic retries, this creates a feedback loop that significantly improves extraction reliability without requiring manual intervention.\n\n资料来源：[README.md:1-50]()\n\n---\n\n## Architecture\n\n### Core Components\n\n```mermaid\ngraph TD\n    A[Client Request] --> B[Pydantic Response Model]\n    B --> C[LLM API Call]\n    C --> D[Response Parsing]\n    D --> E{Validation}\n    E -->|Pass| F[Return Validated Object]\n    E -->|Fail| G[Log Error Message]\n    G --> H{Retry Count < max_retries?}\n    H -->|Yes| I[Retry with Error Context]\n    H -->|No| J[Raise Exception]\n    I --> C\n```\n\n### Validation Pipeline\n\n1. **Initial Request**: User submits a request with a Pydantic `response_model`\n2. **LLM Invocation**: Instructor calls the provider API with function calling parameters\n3. **Response Parsing**: Raw response is parsed into the target Pydantic model\n4. **Validation**: Pydantic validators run on the parsed data\n5. **Retry Decision**: If validation fails and retries remain, re-invoke with error context\n6. **Final Response**: Validated model instance is returned to user\n\n资料来源：[examples/validators/readme.md:1-80]()\n\n---\n\n## Pydantic-Based Validation\n\n### Standard Field Validators\n\nInstructor leverages Pydantic's built-in validation system. Fields defined in response models are automatically validated upon extraction:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\n### Validation Configuration\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `max_retries` | `int` | `3` | Maximum retry attempts after validation failure |\n| `response_model` | `BaseModel` | Required | Pydantic model defining expected output structure |\n| `validation_context` | `dict` | `None` | Additional context passed to validators |\n\n资料来源：[README.md:60-90]()\n\n---\n\n## LLM-Based Validation\n\n### Overview\n\nThe `llm_validator` function enables content-aware validation using the LLM itself. This is useful for semantic checks that cannot be expressed as simple schema rules:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n### How LLM Validation Works\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant Instructor\n    participant LLM\n    participant Validator\n    \n    User->>Instructor: Create response with llm_validator\n    Instructor->>LLM: Initial request\n    LLM-->>Instructor: Response\n    Instructor->>Validator: Validate content\n    Validator->>LLM: Check against constraint\n    alt Validation Passes\n        Validator-->>Instructor: Valid\n        Instructor-->>User: Return model\n    else Validation Fails\n        Validator-->>Instructor: Assertion failed: {reason}\n        Instructor->>LLM: Retry with error message\n        LLM-->>Instructor: Corrected response\n        Instructor->>Validator: Re-validate\n    end\n```\n\n### Validator Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `criteria` | `str` | The validation rule or constraint |\n| `allow_override` | `bool` | Whether the validator can be bypassed with `allow=True` |\n| `model` | `str` | Optional model to use for validation (defaults to response model) |\n\n资料来源：[examples/validators/readme.md:60-120]()\n\n---\n\n## Automatic Retry Mechanism\n\n### Retry Flow\n\nWhen validation fails, Instructor automatically retries the request. The retry process includes:\n\n1. **Error Capture**: The validation error message is extracted\n2. **Context Building**: Error details are formatted into a user message\n3. **Retry Execution**: The original request is repeated with error context\n4. **Iteration**: Process repeats until success or `max_retries` is exhausted\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=3,  # Retry up to 3 times\n)\n```\n\n### Retry Behavior\n\n| Scenario | Behavior |\n|----------|----------|\n| Validation passes | Return validated object immediately |\n| Validation fails (retries available) | Retry with error context |\n| Validation fails (no retries left) | Raise `ValidationError` |\n| API error | Retry with exponential backoff |\n\n资料来源：[README.md:75-95]()\n\n---\n\n## Streaming with Partial Validation\n\nInstructor supports streaming responses with partial validation, allowing real-time feedback as objects are generated:\n\n```python\nfrom instructor import Partial\n\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n):\n    print(partial_user)\n    # Output progression:\n    # User(name=None, age=None)\n    # User(name=\"John\", age=None)\n    # User(name=\"John\", age=25)\n```\n\n### Partial Validation States\n\n```mermaid\ngraph LR\n    A[Start] --> B{name != None}\n    B -->|No| C[Partial: User(name=None, ...)]\n    B -->|Yes| D{age != None}\n    D -->|No| E[Partial: User(name=\"...\", ...)]\n    D -->|Yes| F[Complete: User(...)]\n```\n\n资料来源：[README.md:95-110]()\n\n---\n\n## Hooks for Validation Monitoring\n\nInstructor provides hooks that allow monitoring of validation events during the request lifecycle:\n\n```mermaid\ngraph LR\n    A[Request Start] --> B[Parse Hook]\n    B --> C[LLM Call]\n    C --> D{Validation}\n    D --> E[Success Hook]\n    D --> F[Error Hook]\n    E --> G[Return Result]\n    F --> H[Retry Hook]\n    H -->|Has Retries| C\n    H -->|No Retries| I[Raise Exception]\n```\n\n### Available Hook Types\n\n| Hook | Trigger | Use Case |\n|------|---------|----------|\n| `on_request_start` | Before API call | Log request details |\n| `on_response` | Successful response | Track token usage |\n| `on_parse_error` | JSON parsing failure | Debug malformed output |\n| `on_retry` | Before retry attempt | Log retry attempts |\n| `on_validation_error` | Validation failure | Track failed validations |\n\n资料来源：[examples/hooks/README.md:1-30]()\n\n---\n\n## Error Handling Patterns\n\n### Handling Validation Errors\n\n```python\ntry:\n    qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(\n        model=\"gpt-3.5-turbo\",\n        response_model=QuestionAnswerNoEvil,\n        messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    )\nexcept Exception as e:\n    print(f\"Validation failed after retries: {e}\")\n```\n\n### Common Validation Error Types\n\n| Error Type | Cause | Resolution |\n|------------|-------|------------|\n| `ValidationError` | Pydantic validation failure | Check field constraints |\n| `ParseError` | Malformed JSON response | Model may need adjustment |\n| `AssertionError` | LLM validator rejection | Review validation criteria |\n\n资料来源：[examples/validators/readme.md:100-140]()\n\n---\n\n## Integration with Batch Processing\n\nValidation and retry mechanisms are also available in batch processing scenarios:\n\n```python\nfrom instructor.processing import BatchProcessor\n\nbatch = BatchProcessor(\n    response_model=User,\n    max_retries=3,\n    on_validation_error=lambda e: log_error(e)\n)\n\nbatch.process(messages_file=\"messages.jsonl\")\n```\n\n### Batch Validation Features\n\n- Parallel validation of batch items\n- Per-item retry tracking\n- Aggregated error reporting\n- Configurable failure thresholds\n\n资料来源：[examples/batch_api/README.md:1-60]()\n\n---\n\n## Best Practices\n\n### 1. Define Clear Validation Rules\n\n```python\n# Good: Specific, enforceable rules\n@field_validator('email')\ndef validate_email(cls, v):\n    if '@' not in v:\n        raise ValueError('Invalid email format')\n    return v\n\n# Good: LLM validator for semantic checks\nllm_validator(\"response should be concise and factual\")\n```\n\n### 2. Set Appropriate Retry Limits\n\n| Use Case | Recommended `max_retries` |\n|----------|--------------------------|\n| Simple extraction | 1-2 |\n| Complex nested structures | 3-5 |\n| LLM-validated content | 2-3 |\n\n### 3. Use Descriptive Error Messages\n\nValidation error messages are passed to the LLM during retries. Clear, actionable error messages improve retry success rates.\n\n---\n\n## Summary\n\nInstructor's validation and retry mechanisms provide a powerful abstraction layer for reliable LLM output extraction:\n\n- **Pydantic Integration**: Leverage existing validation patterns\n- **LLM-Based Validation**: Check semantic content quality\n- **Automatic Retries**: Self-correcting extraction pipeline\n- **Streaming Support**: Real-time partial validation\n- **Hook System**: Observable validation lifecycle\n\nTogether, these components create a robust system for building production-grade LLM applications with predictable, validated outputs.\n\n资料来源：[README.md:1-120](), [examples/validators/readme.md:1-150]()\n\n---\n\n<a id='streaming'></a>\n\n## Streaming and Partial Responses\n\n### 相关页面\n\n相关主题：[Validation and Retry Mechanisms](#validation-retries)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [instructor/dsl/partial.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/partial.py)\n- [instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n- [docs/concepts/partial.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/partial.md)\n- [docs/concepts/iterable.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/iterable.md)\n- [examples/partial_streaming/run.py](https://github.com/567-labs/instructor/blob/main/examples/partial_streaming/run.py)\n</details>\n\n# Streaming and Partial Responses\n\n## Overview\n\nStreaming and partial responses are core features in Instructor that enable real-time processing of LLM outputs. Instead of waiting for the complete response to be generated, these features allow developers to receive and process data incrementally as it's being generated by the model.\n\nThe primary purpose of streaming support is to:\n- Provide faster perceived latency by displaying partial results immediately\n- Enable real-time UI updates for interactive applications\n- Support progressive data extraction for long-form content\n- Allow applications to start processing data before the entire response is complete\n\n资料来源：[README.md:streaming support]()\n\n## Architecture\n\nInstructor implements streaming through two complementary abstractions:\n\n1. **Partial** - Represents a partially validated response model\n2. **Iterable** - Represents a stream of validated response models\n\n### Data Flow Architecture\n\n```mermaid\ngraph TD\n    A[LLM API Streaming Response] --> B[Instructor Response Handler]\n    B --> C{Response Mode}\n    C -->|Partial Mode| D[Partial Validator]\n    C -->|Iterable Mode| E[Iterable Validator]\n    D --> F[Partial Response Model]\n    E --> G[Validated Response Objects]\n    F --> H[Application Consumer]\n    G --> H\n```\n\n### Component Overview\n\n| Component | Purpose | File Location |\n|-----------|---------|---------------|\n| `Partial[T]` | Generic wrapper for partial response models | `instructor/dsl/partial.py` |\n| `Iterable[T]` | Generic wrapper for streaming response models | `instructor/dsl/iterable.py` |\n| Response Handler | Processes streaming chunks from LLM providers | Core client implementation |\n| Validation Pipeline | Validates each partial/iterable chunk | Instructor DSL layer |\n\n资料来源：[instructor/dsl/partial.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/partial.py)\n资料来源：[instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n\n## Partial Responses\n\n### What Are Partial Responses?\n\nPartial responses enable receiving incrementally validated data as the LLM generates content. When using `Partial[T]`, each streamed chunk contains a validated response model where some fields may be `None` until the model finishes generating them.\n\n### Usage Pattern\n\n```python\nfrom instructor import Partial\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n# Stream partial responses as they're generated\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n):\n    print(partial_user)\n```\n\n### Evolution of Partial Response\n\nDuring streaming, the response model evolves as follows:\n\n```python\n# Initial state - no fields populated\n# User(name=None, age=None)\n\n# After name is generated\n# User(name=\"John\", age=None)\n\n# After full generation complete\n# User(name=\"John\", age=25)\n```\n\n资料来源：[README.md:Streaming support]()\n资料来源：[docs/concepts/partial.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/partial.md)\n\n## Iterable Responses\n\n### What Are Iterable Responses?\n\nIterable responses handle streams of complete, validated response models. Unlike `Partial[T]` which shows evolution of a single response, `Iterable[T]` represents multiple discrete responses that can be streamed from the LLM.\n\n### Usage Pattern\n\n```python\nfrom instructor import Iterable\n\nclass TaskResult(BaseModel):\n    task_id: str\n    result: str\n    status: str\n\n# Stream multiple validated responses\nfor task in client.chat.completions.create(\n    response_model=Iterable[TaskResult],\n    messages=[{\"role\": \"user\", \"content\": \"Process these items...\"}],\n    stream=True,\n):\n    print(f\"Task {task.task_id}: {task.status}\")\n```\n\n资料来源：[instructor/dsl/iterable.py](https://github.com/567-labs/instructor/blob/main/instructor/dsl/iterable.py)\n资料来源：[docs/concepts/iterable.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/iterable.md)\n\n## API Reference\n\n### Client Method Signature\n\nBoth partial and iterable streaming use the standard client creation method with additional parameters:\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `response_model` | `Type[BaseModel]` | Required | The Pydantic model for validation |\n| `messages` | `List[dict]` | Required | Conversation messages |\n| `stream` | `bool` | `False` | Enable streaming mode |\n| `max_retries` | `int` | `3` | Maximum retry attempts on validation failure |\n| `**kwargs` | Various | Provider-specific | Additional provider parameters |\n\n### Response Type Resolution\n\n| Response Model Wrapper | Return Type | Use Case |\n|------------------------|-------------|----------|\n| `response_model=User` | `User` | Complete, validated single response |\n| `response_model=Partial[User]` | `Generator[User, None, None]` | Progressive single response |\n| `response_model=Iterable[User]` | `Generator[User, None, None]` | Stream of validated responses |\n\n资料来源：[examples/partial_streaming/run.py](https://github.com/567-labs/instructor/blob/main/examples/partial_streaming/run.py)\n\n## Provider Compatibility\n\n### Universal Streaming Support\n\nStreaming is supported across all major LLM providers through a unified interface:\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\nfor partial in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[...],\n    stream=True,\n):\n    print(partial)\n```\n\n### Provider Response Handling\n\nEach provider implements streaming through provider-specific response handlers:\n\n```mermaid\ngraph LR\n    A[Provider API] --> B[Provider Utils]\n    B --> C[Standardized Chunk Format]\n    C --> D[Instructor DSL]\n    D --> E[Partial/Iterable Validator]\n    E --> F[Validated Response]\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Validation Behavior\n\n### Validation During Streaming\n\nPartial and iterable responses undergo the same validation as non-streaming responses. The key difference is that validation occurs on each streamed chunk rather than on a complete response.\n\n### Validation Pipeline Flow\n\n```mermaid\ngraph TD\n    A[Stream Chunk Received] --> B[Parse to Response Model]\n    B --> C{Validation Pass?}\n    C -->|Yes| D[Yield Validated Partial]\n    C -->|No| E{Retry Available?}\n    E -->|Yes| F[Retry with Error Context]\n    E -->|No| G[Raise Validation Error]\n    D --> H[Next Chunk]\n    H --> A\n```\n\n### Error Handling\n\nWhen validation fails during streaming, Instructor can retry automatically if `max_retries` is configured:\n\n```python\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n    max_retries=3,  # Automatic retry on validation failure\n):\n    print(partial_user)\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Use Cases\n\n### Real-Time UI Updates\n\nPartial responses are ideal for applications requiring immediate visual feedback:\n\n```python\nfrom instructor import Partial\n\nclass SearchResult(BaseModel):\n    title: str\n    url: str\n    snippet: str\n\n# Update UI as results arrive\nfor partial_result in client.chat.completions.create(\n    response_model=Partial[SearchResult],\n    messages=[{\"role\": \"user\", \"content\": f\"Search for: {query}\"}],\n    stream=True,\n):\n    update_ui(partial_result)  # Progressive rendering\n```\n\n### Long-Running Task Processing\n\nIterable responses suit scenarios where the LLM generates multiple distinct outputs:\n\n```python\nclass AnalysisReport(BaseModel):\n    section: str\n    findings: List[str]\n    confidence: float\n\nfor report_section in client.chat.completions.create(\n    response_model=Iterable[AnalysisReport],\n    messages=[{\"role\": \"user\", \"content\": \"Analyze this document...\"}],\n    stream=True,\n):\n    save_section(report_section)\n```\n\n### Progressive Data Extraction\n\nExtract complex nested structures incrementally:\n\n```python\nclass Document(BaseModel):\n    title: str\n    author: str\n    sections: List[\"Section\"]\n\nclass Section(BaseModel):\n    heading: str\n    content: str\n\nfor partial_doc in client.chat.completions.create(\n    response_model=Partial[Document],\n    messages=[{\"role\": \"user\", \"content\": \"Extract document structure...\"}],\n    stream=True,\n):\n    display_preview(partial_doc)\n```\n\n## Best Practices\n\n### Performance Considerations\n\n| Practice | Recommendation | Rationale |\n|----------|----------------|-----------|\n| Batch Processing | Use `Iterable[T]` for multiple items | Reduces API call overhead |\n| UI Responsiveness | Prefer `Partial[T]` for progressive updates | Lower perceived latency |\n| Validation Overhead | Set appropriate `max_retries` | Balance reliability vs. performance |\n\n### Error Handling Strategy\n\n```python\ntry:\n    for partial in client.chat.completions.create(\n        response_model=Partial[User],\n        messages=[...],\n        stream=True,\n        max_retries=3,\n    ):\n        process(partial)\nexcept ValidationError as e:\n    handle_validation_failure(e)\nexcept Exception as e:\n    handle_stream_error(e)\n```\n\n### Memory Efficiency\n\nWhen processing large streams, consume the generator incrementally rather than collecting all results:\n\n```python\n# Memory efficient - processes one at a time\nfor item in client.chat.completions.create(\n    response_model=Iterable[LargeModel],\n    messages=[...],\n    stream=True,\n):\n    write_to_disk(item)\n\n# Memory intensive - collects all results\nall_items = list(client.chat.completions.create(\n    response_model=Iterable[LargeModel],\n    messages=[...],\n    stream=True,\n))\n```\n\n## Related Concepts\n\n- **Retry Logic**: Streaming integrates with Instructor's automatic retry mechanism for validation failures\n- **Hooks System**: Hooks can be attached to streaming operations for monitoring and logging\n- **Provider Architecture**: Each LLM provider implements streaming through provider-specific utilities\n\n## Summary\n\nStreaming and partial responses in Instructor provide powerful mechanisms for real-time data processing with LLM outputs. The `Partial[T]` wrapper enables progressive validation of single responses, while `Iterable[T]` supports streaming multiple discrete responses. Both features maintain full integration with Pydantic validation, retry logic, and all supported LLM providers through a unified API.\n\n---\n\n<a id='providers'></a>\n\n## LLM Provider Support\n\n### 相关页面\n\n相关主题：[Unified Provider Interface](#from-provider), [Installation and Setup](#installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n- [instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n- [examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n- [examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n- [examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n</details>\n\n# LLM Provider Support\n\n## Overview\n\nInstructor provides a unified API for working with multiple Large Language Model (LLM) providers. The library abstracts provider-specific implementations behind a common interface, allowing developers to switch between providers without modifying their application logic.\n\nThe `from_provider()` method serves as the primary entry point for initializing clients across all supported providers 资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md).\n\n## Supported Providers\n\nInstructor supports the following LLM providers through a consistent API:\n\n| Provider | Client Function | Model Examples |\n|----------|------------------|----------------|\n| OpenAI | `from_provider(\"openai/...\")` | gpt-4o, gpt-4o-mini, gpt-4-turbo |\n| Anthropic | `from_provider(\"anthropic/...\")` | claude-3-5-sonnet, claude-3-opus |\n| Google | `from_provider(\"google/...\")` | gemini-2.0-flash-001, gemini-pro |\n| Ollama | `from_provider(\"ollama/...\")` | llama3.2 (local models) |\n| Groq | `from_provider(\"groq/...\")` | llama-3.1-8b-instant |\n| Cohere | `from_provider(\"cohere/...\")` | Command R+ |\n| Mistral | `from_provider(\"mistral/...\")` | Mistral Large |\n| Fireworks | `from_provider(\"fireworks/...\")` | fireworks models |\n| Perplexity | `from_provider(\"perplexity/...\")` | perplexity models |\n| Cerebras | `from_provider(\"cerebras/...\")` | cerebras models |\n| XAI | `from_provider(\"xai/...\")` | xai models |\n| Writer | `from_provider(\"writer/...\")` | writer models |\n| VertexAI | `from_provider(\"vertexai/...\")` | vertexai models |\n| Bedrock | `from_provider(\"bedrock/...\")` | bedrock models |\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Provider Architecture\n\n### Directory Structure\n\nEach provider is organized in its own subdirectory within `instructor/providers/`:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n### Provider Classification\n\nProviders are categorized based on their implementation complexity:\n\n#### Providers with Both `client.py` and `utils.py`\n\nThese providers require custom response handling logic and utility functions:\n\n- **anthropic**\n- **bedrock**\n- **cerebras**\n- **cohere**\n- **fireworks**\n- **gemini**\n- **mistral**\n- **perplexity**\n- **writer**\n- **xai**\n\n#### Providers with Only `client.py`\n\nThese are simpler providers using standard response handling from the core:\n\n- **genai**\n- **groq**\n- **vertexai**\n\n#### Special Case: OpenAI\n\nOpenAI doesn't have a `client.py` because `from_openai()` is defined in `core/client.py`. This is because OpenAI is the reference implementation that other providers are based on.\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Unified Client API\n\n### Basic Initialization\n\nAll providers use the same initialization pattern:\n\n```python\nclient = instructor.from_provider(\"provider/model-name\")\n```\n\n### Usage Example\n\n```python\nfrom instructor import from_provider\n\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### API Key Configuration\n\nAPI keys can be passed directly to the `from_provider()` method:\n\n```python\n# OpenAI with explicit API key\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\n\n# Anthropic with explicit API key\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\n\n# Groq with explicit API key\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\nAlternatively, providers respect environment variables for API key configuration.\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Response Model Integration\n\nAll providers support Pydantic response models for structured outputs:\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### Validator Support\n\nProviders work seamlessly with Pydantic validators:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n### LLM Validators\n\nCustom validation using `llm_validator` is supported across all providers:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n资料来源：[examples/validators/readme.md](https://github.com/567-labs/instructor/blob/main/examples/validators/readme.md)\n\n## Automatic Retries\n\nFailed validations are automatically retried with the error message:\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=2,\n)\n```\n\n资料来源：[README.md](https://github.com/567-labs/instructor/blob/main/README.md)\n\n## Batch Processing Support\n\nProviders support batch API operations through the unified `BatchProcessor` interface:\n\n### Supported Batch Operations\n\n```bash\n# Create batch using CLI\ninstructor batch create \\\n  --messages-file messages.jsonl \\\n  --model \"openai/gpt-4o-mini\" \\\n  --response-model \"examples.User\" \\\n  --output-file batch_requests.jsonl\n\n# Submit the batch\ninstructor batch create-from-file \\\n  --file-path batch_requests.jsonl \\\n  --model \"openai/gpt-4o-mini\"\n```\n\n### Provider-Specific Batch Features\n\n| Provider | Batch Endpoint | Notes |\n|----------|----------------|-------|\n| OpenAI | `client.batches.create()` | Standard batch API |\n| Anthropic | `client.beta.messages.batches` | Uses beta API endpoints |\n| Google | Simulation mode | Requires GCS for production |\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n### Batch Test Script\n\nA test script is available to validate batch processing across providers:\n\n```bash\n# Test OpenAI\nexport OPENAI_API_KEY=\"your-api-key\"\npython run_batch_test.py create --model \"openai/gpt-4o-mini\"\n\n# Test Anthropic\nexport ANTHROPIC_API_KEY=\"your-api-key\"\npython run_batch_test.py create --model \"anthropic/claude-3-5-sonnet-20241022\"\n\n# Test Google (simulation mode)\npython run_batch_test.py create --model \"google/gemini-2.0-flash-001\"\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## Hooks System\n\nProviders integrate with Instructor's hooks system for monitoring and debugging:\n\n### Available Hook Events\n\n- **Request hooks**: Execute before API calls\n- **Response hooks**: Execute after successful responses\n- **Error hooks**: Execute on completion errors\n- **Retry hooks**: Execute on retry attempts\n\n### Hook Implementation Example\n\n```python\ndef on_request(detail):\n    print(f\"🔍 Request: {detail}\")\n\ndef on_response(detail):\n    print(f\"✅ Response: {detail}\")\n\ndef on_error(detail):\n    print(f\"❌ Error: {detail}\")\n\nclient = instructor.from_provider(\"openai/gpt-4o\")\nclient.attach_hook(\"request\", on_request)\nclient.attach_hook(\"response\", on_response)\nclient.attach_hook(\"error\", on_error)\n```\n\n资料来源：[examples/hooks/README.md](https://github.com/567-labs/instructor/blob/main/examples/hooks/README.md)\n\n## Fine-tuning Integration\n\nAll providers support Instructor's fine-tuning capabilities:\n\n```python\n# Generate fine-tuning data\npython three_digit_mul.py\n\n# Create fine-tuning job\ninstructor jobs create-from-file math_finetunes.jsonl\n\n# With validation data\ninstructor jobs create-from-file math_finetunes.jsonl \\\n  --n-epochs 4 \\\n  --validation-file math_finetunes_val.jsonl\n```\n\n资料来源：[examples/distilations/readme.md](https://github.com/567-labs/instructor/blob/main/examples/distilations/readme.md)\n\n## Provider Selection Guidelines\n\n### Flowchart: Provider Selection\n\n```mermaid\ngraph TD\n    A[Select Provider] --> B{Need Local Model?}\n    B -->|Yes| C[Ollama]\n    B -->|No| D{Need Specific Capabilities?}\n    D -->|Anthropic Claude| E[Anthropic]\n    D -->|Google Gemini| F[Google]\n    D -->|OpenAI GPT| G[OpenAI]\n    D -->|Low Cost| H[Groq]\n    D -->|Custom| I[Other Providers]\n    G --> J[Create Client]\n    E --> J\n    F --> J\n    C --> J\n    H --> J\n    I --> J\n    J --> K[Use with Response Model]\n```\n\n### Selection Criteria\n\n| Use Case | Recommended Provider |\n|----------|---------------------|\n| General purpose, best quality | OpenAI GPT-4o |\n| Long context, reasoning | Anthropic Claude |\n| Fast inference, cost-effective | Groq |\n| Multimodal capabilities | Google Gemini |\n| Local/private deployment | Ollama |\n| AWS integration | Bedrock |\n| Complex reasoning tasks | xAI |\n\n## Adding New Providers\n\nWhen adding a new provider to Instructor:\n\n1. Create a new subdirectory under `instructor/providers/`\n2. Add an `__init__.py` file\n3. Implement `client.py` for the provider factory function\n4. Add `utils.py` for provider-specific response handling\n5. Update the unified `from_provider()` dispatcher\n\n资料来源：[instructor/providers/README.md](https://github.com/567-labs/instructor/blob/main/instructor/providers/README.md)\n\n## Error Handling\n\n### Common Provider Errors\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `API key not set` | Missing environment variable | Set appropriate API key |\n| `Invalid model format` | Incorrect model string format | Use `provider/model-name` format |\n| `Unsupported provider` | Provider not in registry | Use supported provider names |\n| `Rate limit exceeded` | Too many requests | Implement backoff or reduce concurrency |\n\n### Error Recovery\n\nProviders support automatic retry with exponential backoff for transient failures:\n\n```python\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=3,\n)\n```\n\n资料来源：[examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md)\n\n## See Also\n\n- [Core Client Implementation](../instructor/client.md)\n- [Response Models and Validation](./response_models.md)\n- [Hooks System](./hooks.md)\n- [Batch Processing](./batch_processing.md)\n- [Fine-tuning](./fine_tuning.md)\n\n---\n\n<a id='from-provider'></a>\n\n## Unified Provider Interface\n\n### 相关页面\n\n相关主题：[LLM Provider Support](#providers), [Core Components Architecture](#core-components)\n\n<details>\n<summary>Related Source Files</summary>\n\nThe following source files were referenced (note: some files were not available in the current context):\n\n- [instructor/auto_client.py](https://github.com/567-labs/instructor/blob/main/instructor/auto_client.py) - Main unified client implementation\n- [docs/concepts/from_provider.md](https://github.com/567-labs/instructor/blob/main/docs/concepts/from_provider.md) - Conceptual documentation for the provider interface\n- [instructor/utils/providers.py](https://github.com/567-labs/instructor/blob/main/instructor/utils/providers.py) - Provider utility functions\n- [README.md](https://github.com/567-labs/instructor/blob/main/README.md) - Primary documentation\n- [providers/README.md](https://github.com/567-labs/instructor/blob/main/providers/README.md) - Provider organization documentation\n- [examples/batch_api/README.md](https://github.com/567-labs/instructor/blob/main/examples/batch_api/README.md) - Batch API with provider examples\n\n</details>\n\n# Unified Provider Interface\n\n## Overview\n\nThe **Unified Provider Interface** is a core architectural feature of the Instructor library that provides a single, consistent API for interacting with multiple Large Language Model (LLM) providers. This abstraction eliminates provider-specific code patterns and allows developers to switch between different LLM backends without modifying their application logic.\n\nThe unified interface is accessed through the `from_provider()` factory function, which accepts provider/model strings in the format `\"provider/model-name\"` and returns a configured client instance that follows a standardized interface. 资料来源：[README.md](README.md)\n\n## Architecture\n\n### Core Design Principles\n\n1. **Provider Agnosticism**: All supported providers implement the same method signatures\n2. **Automatic Model Detection**: Provider is inferred from the model string prefix\n3. **Transparent Retries**: Failed validations are automatically retried with error context\n4. **Type Safety**: Full Pydantic integration for response validation\n\n### Supported Providers\n\nThe unified interface supports multiple LLM providers through a consistent abstraction layer:\n\n| Provider | Model Prefix | Special Features |\n|----------|--------------|------------------|\n| OpenAI | `openai/` | Reference implementation |\n| Anthropic | `anthropic/` | Beta API endpoints |\n| Google | `google/` | Gemini Pro/Vision |\n| Ollama | `ollama/` | Local models |\n| Groq | `groq/` | Fast inference |\n| Mistral | `mistral/` | European models |\n| Cohere | `cohere/` | Command models |\n| AWS Bedrock | `bedrock/` | Cloud deployment |\n| Cerebras | `cerebras/` | Optimized inference |\n| Fireworks | `fireworks/` | High performance |\n| Perplexity | `perplexity/` | Search-focused |\n| Writer | `writer/` | Enterprise content |\n| XAI | `xai/` | Elon Musk's xAI |\n\n资料来源：[README.md](README.md), [providers/README.md](providers/README.md)\n\n## Usage\n\n### Basic Initialization\n\n```python\nimport instructor\n\n# Create unified client for any provider\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Use the same API regardless of provider\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n### Provider Comparison\n\n```python\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n```\n\n资料来源：[README.md](README.md)\n\n### API Key Configuration\n\nThe unified interface supports multiple ways to provide API credentials:\n\n| Method | Description |\n|--------|-------------|\n| Environment Variables | `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc. |\n| Direct Parameter | `client = from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")` |\n\n```python\n# With API keys directly (no environment variables needed)\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n```\n\n资料来源：[README.md](README.md)\n\n## Provider Directory Structure\n\nEach provider implementation follows a standardized directory structure:\n\n```\nproviders/\n├── provider_name/\n│   ├── __init__.py\n│   ├── client.py      # Provider-specific client factory (optional)\n│   └── utils.py       # Provider-specific utilities (optional)\n```\n\n### Provider Categories\n\n**Providers with both `client.py` and `utils.py`:**\n- anthropic, bedrock, cerebras, cohere, fireworks, gemini, mistral, perplexity, writer, xai\n\n**Providers with only `client.py`:**\n- genai, groq, vertexai\n\n**Special Case - OpenAI:**\n- OpenAI doesn't have a `client.py` because `from_openai()` is defined in `core/client.py`\n- OpenAI is the reference implementation that other providers are based on\n\n资料来源：[providers/README.md](providers/README.md)\n\n## API Methods\n\n### Create Method\n\nThe primary method for generating structured responses:\n\n```python\nresponse = client.chat.completions.create(\n    response_model=User,  # Pydantic model\n    messages=[...],\n    model=\"...\",\n    max_retries=3,  # Automatic retry on validation failure\n)\n```\n\n### Alternative API Patterns\n\nFor simplified usage, these patterns are also supported:\n\n```python\n# All equivalent to client.chat.completions.create\nclient.create()\nclient.create_partial()\nclient.create_iterable()\nclient.create_with_completion()\n```\n\n资料来源：[scripts/README.md](scripts/README.md)\n\n## Response Model Integration\n\nThe unified interface seamlessly integrates with Pydantic for type validation:\n\n### Basic Model Definition\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n```\n\n### Model with Validation\n\n```python\nfrom pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v < 0:\n            raise ValueError('Age must be positive')\n        return v\n```\n\nWhen validation fails, Instructor automatically retries the request with the error message:\n\n```python\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n资料来源：[README.md](README.md)\n\n## Batch Processing\n\nThe unified interface supports batch processing across all providers through the `BatchProcessor` class:\n\n```python\nfrom instructor.batch import BatchProcessor\n\nprocessor = BatchProcessor()\n\n# Create batch with provider detection\nprocessor.create_batch(\n    messages=test_messages,\n    model=\"openai/gpt-4o-mini\",\n    response_model=User,\n)\n```\n\n### Provider-Specific Batch Support\n\n| Provider | Batch API | Notes |\n|----------|-----------|-------|\n| OpenAI | `client.batches.create()` | Full support |\n| Anthropic | `client.beta.messages.batches` | Beta endpoints |\n| Google | Simulation mode | Requires GCS setup |\n\n资料来源：[examples/batch_api/README.md](examples/batch_api/README.md)\n\n## Workflow Diagram\n\n```mermaid\ngraph TD\n    A[User Code] --> B[from_provider factory]\n    B --> C{Parse provider/model}\n    C -->|openai| D[OpenAI Client]\n    C -->|anthropic| E[Anthropic Client]\n    C -->|google| F[Google Client]\n    C -->|other| G[Other Provider Client]\n    \n    D --> H[Unified API Layer]\n    E --> H\n    F --> H\n    G --> H\n    \n    H --> I[Provider-Specific Transport]\n    I --> J{Response Validation}\n    J -->|Pass| K[Return Typed Response]\n    J -->|Fail| L[Retry with Error Context]\n    L --> H\n```\n\n## Advanced Configuration\n\n### Custom Validators\n\nYou can add custom LLM-based validation:\n\n```python\nfrom typing_extensions import Annotated\nfrom pydantic import BeforeValidator\nfrom instructor import llm_validator\n\nclass QuestionAnswerNoEvil(BaseModel):\n    question: str\n    answer: Annotated[\n        str,\n        BeforeValidator(\n            llm_validator(\"don't say objectionable things\", allow_override=True)\n        ),\n    ]\n```\n\n### Retry Configuration\n\n```python\n# Allow retries on validation failure\nqa = client.chat.completions.create(\n    response_model=QuestionAnswer,\n    max_retries=2,\n    messages=[...],\n)\n```\n\n资料来源：[examples/validators/readme.md](examples/validators/readme.md)\n\n## Migration from Legacy Patterns\n\n### Old Patterns to Unified Interface\n\n| Old Pattern | Unified Pattern |\n|-------------|------------------|\n| `instructor.from_openai(OpenAI())` | `instructor.from_provider(\"openai/model-name\")` |\n| `instructor.from_anthropic(Anthropic())` | `instructor.from_provider(\"anthropic/model-name\")` |\n| `instructor.patch(OpenAI())` | `instructor.from_provider(\"openai/model-name\")` |\n\n### Automated Migration Scripts\n\nThe repository includes scripts to automate migration:\n\n```bash\n# Replace old patterns automatically\npython scripts/fix_old_patterns.py --dry-run\npython scripts/fix_old_patterns.py\n\n# Audit documentation for old patterns\npython scripts/audit_patterns.py\n```\n\n资料来源：[scripts/README.md](scripts/README.md)\n\n## Summary\n\nThe Unified Provider Interface is a fundamental architectural feature that enables Instructor to work seamlessly across multiple LLM providers. By abstracting provider-specific details behind a common API:\n\n- Developers can switch providers without code changes\n- Response validation works consistently across all providers\n- Automatic retries provide resilience against transient failures\n- The Pydantic integration ensures type safety throughout\n\nThis design philosophy makes Instructor highly adaptable and future-proof, as new providers can be added without affecting existing code.\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：567-labs/instructor\n\n摘要：发现 21 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：安装坑 - 来源证据：Documentation (at least Google-related) is an outdated mess.。\n\n## 1. 安装坑 · 来源证据：Documentation (at least Google-related) is an outdated mess.\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Documentation (at least Google-related) is an outdated mess.\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b87b003416cd4308bc863f0cd66a68fd | https://github.com/567-labs/instructor/issues/2289 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v1.13.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v1.13.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f3c1e8416a744b51b5691317c10bc5bf | https://github.com/567-labs/instructor/releases/tag/v1.13.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 配置坑 · 来源证据：v1.12.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.12.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9b8236f58f8641c586777618a838409f | https://github.com/567-labs/instructor/releases/tag/v1.12.0 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 4. 配置坑 · 来源证据：v1.14.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_053ef3382ace48778d05ef006d87cead | https://github.com/567-labs/instructor/releases/tag/v1.14.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 来源证据：v1.14.3\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.3\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_d18c003929614c7097d16742ec94cc8c | https://github.com/567-labs/instructor/releases/tag/v1.14.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 6. 配置坑 · 来源证据：v1.14.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.4\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_76987134f9a747d685958a5e98f3b51a | https://github.com/567-labs/instructor/releases/tag/v1.14.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：v1.15.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.15.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_430369db61e440e5a4b575e2b3618464 | https://github.com/567-labs/instructor/releases/tag/v1.15.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 8. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:653589102 | https://github.com/567-labs/instructor | README/documentation is current enough for a first validation pass.\n\n## 9. 运行坑 · 来源证据：v1.14.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个运行相关的待验证问题：v1.14.2\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_fd561faf78f147518bcda7a0370a9a4f | https://github.com/567-labs/instructor/releases/tag/v1.14.2 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：Catching IncompleteOutputException : not possible as presently documented / tested.\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Catching IncompleteOutputException : not possible as presently documented / tested.\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dc0f4256859740f8a4cacd1731514783 | https://github.com/567-labs/instructor/issues/2273 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b982358c78a346bfaa26b428e00968bb | https://github.com/567-labs/instructor/issues/2291 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：bump lightllm upper bound for recent vulnerabililties\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bump lightllm upper bound for recent vulnerabililties\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2ae9c53479204c778e56a8b4b3feb404 | https://github.com/567-labs/instructor/issues/2290 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 16. 安全/权限坑 · 来源证据：logger.debug in response.py leaks api_key verbatim via new_kwargs\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：logger.debug in response.py leaks api_key verbatim via new_kwargs\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2076a35fb27a4c119141e9f57acdf9bc | https://github.com/567-labs/instructor/issues/2265 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 17. 安全/权限坑 · 来源证据：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry m…\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry message\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_0ab343e8383b4d89bbe8eeea25cc69d8 | https://github.com/567-labs/instructor/issues/2277 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 18. 安全/权限坑 · 来源证据：v1.14.5\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.14.5\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_e73ef57918504fe88cf0af969c414ca1 | https://github.com/567-labs/instructor/releases/tag/v1.14.5 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v1.15.1\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.15.1\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_ef102fc17ae84e319f80cfd4cc306eaa | https://github.com/567-labs/instructor/releases/tag/v1.15.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | issue_or_pr_quality=unknown\n\n## 21. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | release_recency=unknown\n\n<!-- canonical_name: 567-labs/instructor; human_manual_source: deepwiki_human_wiki -->\n",
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "Human Manual / 人类版说明书"
    },
    "pitfall_log": {
      "asset_id": "pitfall_log",
      "filename": "PITFALL_LOG.md",
      "markdown": "# Pitfall Log / 踩坑日志\n\n项目：567-labs/instructor\n\n摘要：发现 21 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：安装坑 - 来源证据：Documentation (at least Google-related) is an outdated mess.。\n\n## 1. 安装坑 · 来源证据：Documentation (at least Google-related) is an outdated mess.\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Documentation (at least Google-related) is an outdated mess.\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b87b003416cd4308bc863f0cd66a68fd | https://github.com/567-labs/instructor/issues/2289 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v1.13.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v1.13.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f3c1e8416a744b51b5691317c10bc5bf | https://github.com/567-labs/instructor/releases/tag/v1.13.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 配置坑 · 来源证据：v1.12.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.12.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9b8236f58f8641c586777618a838409f | https://github.com/567-labs/instructor/releases/tag/v1.12.0 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 4. 配置坑 · 来源证据：v1.14.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_053ef3382ace48778d05ef006d87cead | https://github.com/567-labs/instructor/releases/tag/v1.14.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 来源证据：v1.14.3\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.3\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_d18c003929614c7097d16742ec94cc8c | https://github.com/567-labs/instructor/releases/tag/v1.14.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 6. 配置坑 · 来源证据：v1.14.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.14.4\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_76987134f9a747d685958a5e98f3b51a | https://github.com/567-labs/instructor/releases/tag/v1.14.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：v1.15.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v1.15.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_430369db61e440e5a4b575e2b3618464 | https://github.com/567-labs/instructor/releases/tag/v1.15.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 8. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:653589102 | https://github.com/567-labs/instructor | README/documentation is current enough for a first validation pass.\n\n## 9. 运行坑 · 来源证据：v1.14.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个运行相关的待验证问题：v1.14.2\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_fd561faf78f147518bcda7a0370a9a4f | https://github.com/567-labs/instructor/releases/tag/v1.14.2 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:653589102 | https://github.com/567-labs/instructor | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：Catching IncompleteOutputException : not possible as presently documented / tested.\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Catching IncompleteOutputException : not possible as presently documented / tested.\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dc0f4256859740f8a4cacd1731514783 | https://github.com/567-labs/instructor/issues/2273 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：RESPONSES_TOOLS streaming drops reasoning summary events (summary: auto)\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_b982358c78a346bfaa26b428e00968bb | https://github.com/567-labs/instructor/issues/2291 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：bump lightllm upper bound for recent vulnerabililties\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bump lightllm upper bound for recent vulnerabililties\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2ae9c53479204c778e56a8b4b3feb404 | https://github.com/567-labs/instructor/issues/2290 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 16. 安全/权限坑 · 来源证据：logger.debug in response.py leaks api_key verbatim via new_kwargs\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：logger.debug in response.py leaks api_key verbatim via new_kwargs\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2076a35fb27a4c119141e9f57acdf9bc | https://github.com/567-labs/instructor/issues/2265 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 17. 安全/权限坑 · 来源证据：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry m…\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：reask_anthropic_tools retry fails with HTTP 400 on AWS Bedrock — ToolUseBlock.caller=None serialized as null in retry message\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_0ab343e8383b4d89bbe8eeea25cc69d8 | https://github.com/567-labs/instructor/issues/2277 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 18. 安全/权限坑 · 来源证据：v1.14.5\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.14.5\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_e73ef57918504fe88cf0af969c414ca1 | https://github.com/567-labs/instructor/releases/tag/v1.14.5 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v1.15.1\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v1.15.1\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_ef102fc17ae84e319f80cfd4cc306eaa | https://github.com/567-labs/instructor/releases/tag/v1.15.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | issue_or_pr_quality=unknown\n\n## 21. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:653589102 | https://github.com/567-labs/instructor | release_recency=unknown\n",
      "summary": "用户实践前最可能遇到的身份、安装、配置、运行和安全坑。",
      "title": "Pitfall Log / 踩坑日志"
    },
    "prompt_preview": {
      "asset_id": "prompt_preview",
      "filename": "PROMPT_PREVIEW.md",
      "markdown": "# instructor - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for 567-labs/instructor.\n\nProject:\n- Name: instructor\n- Repository: https://github.com/567-labs/instructor\n- Summary: structured outputs for llms\n- Host target: chatgpt\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: structured outputs for llms\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: structured outputs for llms\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. introduction: Introduction to Instructor. Produce one small intermediate artifact and wait for confirmation.\n2. getting-started: Getting Started with Instructor. Produce one small intermediate artifact and wait for confirmation.\n3. core-components: Core Components Architecture. Produce one small intermediate artifact and wait for confirmation.\n4. response-models: Response Models and Type Safety. Produce one small intermediate artifact and wait for confirmation.\n5. validation-retries: Validation and Retry Mechanisms. Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/567-labs/instructor\n- https://github.com/567-labs/instructor#readme\n- README.md\n- instructor/__init__.py\n- docs/getting-started.md\n- docs/learning/getting_started/first_extraction.md\n- examples/simple-extraction/user.py\n- instructor/core/client.py\n- instructor/core/hooks.py\n- instructor/core/retry.py\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n",
      "summary": "不安装项目也能感受能力节奏的安全试用 Prompt。",
      "title": "Prompt Preview / 安装前试用 Prompt"
    },
    "quick_start": {
      "asset_id": "quick_start",
      "filename": "QUICK_START.md",
      "markdown": "# Quick Start / 官方入口\n\n项目：567-labs/instructor\n\n## 官方安装入口\n\n### Python / pip · 官方安装入口\n\n```bash\npip install instructor\n```\n\n来源：https://github.com/567-labs/instructor#readme\n\n## 来源\n\n- repo: https://github.com/567-labs/instructor\n- docs: https://github.com/567-labs/instructor#readme\n",
      "summary": "从项目官方 README 或安装文档提取的开工入口。",
      "title": "Quick Start / 官方入口"
    }
  },
  "validation_id": "dval_8e661cfaee704158990079c366c444a8"
}
