Skip to content

feat(ai): constrain structured replies on the claude, openai and copilot providers #1419

Closed

Description

@dan-petty

Problem

Since #1363, chat_structured tells every provider the reply's schema in the system message, but only two get a wire-level constraint: the gateway provider sends response_format (json_schema, no strict) and the ollama provider sends format. The claude, openai and copilot providers are prompt-only, so their replies can still drift from the schema and cost a reflection retry, or fail the item after it.

OpenAI's strict structured outputs need every property listed in required and additionalProperties: false, so a pydantic model's schema needs a strict-compatible transform first (pydantic-ai ships OpenAIJsonSchemaTransformer). Anthropic's API constrains output through a tool's input_schema.

Proposed remedy

Add each provider's native mechanism once #595's probes show which deployments honour it, reusing the schema transform from the library rather than a hand-written one. A provider whose deployment doesn't honour it stays prompt-only, and the provider docs say so.

Acceptance criteria

  • A request-body test per provider asserts the constraint it sends, or asserts that it sends none and why.
  • The schema transform comes from an existing dependency; no hand-rolled schema rewriting.
  • Tests are offline, each call phase stays under 1 s, and uv run devops ci passes.

Found while delivering #1363. Related: #1363, #595.

Proposed design

Problem statement

The claude, openai, and copilot providers in chat_structured rely only on a prompt-level schema instruction. Their replies can drift from the expected schema, causing a reflection retry or an item failure. The gateway and ollama providers already send a wire-level constraint, but the other three do not. This item adds the native constraint for each of those three providers using pydantic-ai output modes.

Acceptance criteria

  • Criterion 1: A request-body test per provider (claude, openai, copilot) asserts the constraint it sends, or asserts that it sends none with a stated reason.
    Verification: Run the per-provider test suite. Each test inspects the outgoing request body and asserts the presence or absence of the constraint field.
  • Criterion 2: The schema transform uses pydantic-ai's existing OpenAIJsonSchemaTransformer; no hand-rolled schema rewriting is added.
    Verification: Search the diff for any new schema-transformation function. Confirm the only transform imported is OpenAIJsonSchemaTransformer from pydantic_ai.profiles.openai.
  • Criterion 3: All tests are offline, each call phase stays under 1 s, and uv run devops ci passes.
    Verification: Run uv run devops ci in a clean environment. Confirm no network calls in tests, each test phase completes under 1 s, and the full CI pipeline exits 0.

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    scope/ai
    source/agent
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. It reduces schema-drift retries and failures across three providers but the system already functions via prompt-only constraints, so it is an important quality improvement rather than a blocking defect.
    • Value: Medium. Eliminating prompt-only drift for claude, openai, and copilot saves reflection retries and prevents item failures, a meaningful reliability gain for users relying on structured outputs.
    • Effort: Medium. Three providers each need their native constraint wired in plus a shared schema transform from an existing dependency and per-provider request-body tests, but the heavy lifting (transform library) is already available.
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Owner decision on #1001, 2026-10-08: the model seam is pydantic-ai models. This item's per-provider constraint then comes from pydantic-ai's output modes (NativeOutput, ToolOutput, PromptedOutput) as each provider's profile supports them, rather than from each SDK's own mechanism. The acceptance criterion stays a request-body test per provider. Land it on #1001's seam.

  4. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Priority: P2-Medium. The change improves correctness and reliability of AI responses, but is not critical for core functionality.
    • Value: High. Improves data consistency and reduces retries in AI interactions which benefits end users.
    • Effort: Medium. Requires integration with multiple providers and testing, but reuses existing schema transforms.
    • Related: refactor(ai): one structured-output path for validate, repair, reflect and retry #1003, which asks for a different change. Both items work on structured outputs; item 1003 refactors the validation path while this item adds constraints to providers.
  5. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at d509dba (see proposed design in issue body).

  6. added
    priority/p2-medium
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  7. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/featurevalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions