Skip to content

Conversation

@koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Dec 17, 2025

TL;DR

Added support for Anthropic's beta API to enable strict structured output formatting.

What changed?

  • Created a new beta package within the Anthropic provider implementation
  • Implemented AnthropicBetaProvider class that uses Anthropic's beta API
  • Added utility functions for encoding requests and decoding responses with the beta API
  • Modified the main AnthropicProvider to conditionally use the beta provider when strict formatting is requested
  • Updated error messages to include model ID in formatting mode errors
  • Reorganized existing Anthropic utilities into a standard package

How to test?

  1. Use the Anthropic provider with a model that supports strict structured output formatting:

    from mirascope import LLM
    from pydantic import BaseModel
    
    class MyOutput(BaseModel):
        name: str
        age: int
    
    llm = LLM(model="anthropic/claude-3-opus-20240229")
    response = llm.format(MyOutput, mode="strict").call("Generate a person's details")
    print(response.content)  # Will be a properly typed MyOutput instance
  2. Verify that appropriate error messages are shown when using models that don't support strict formatting.

Why make this change?

Anthropic's beta API provides better support for strict structured output formatting, which allows for more reliable parsing of model outputs into Pydantic models. This change enables users to get properly typed outputs from Anthropic models that support this feature, improving type safety and reducing the need for error handling around parsing.

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
v2-docs 1adfb73 Dec 17 2025, 03:56 AM

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 17, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
v2-docs 9fe7369 Dec 18 2025, 07:26 PM

@koxudaxi koxudaxi marked this pull request as ready for review December 17, 2025 03:57
@koxudaxi koxudaxi requested a review from willbakst as a code owner December 17, 2025 03:57
@koxudaxi koxudaxi force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch 3 times, most recently from 0e55905 to cc8cacd Compare December 17, 2025 04:28
@koxudaxi koxudaxi force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch 6 times, most recently from 18a1591 to e974ef1 Compare December 17, 2025 04:58
@koxudaxi koxudaxi force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch from e974ef1 to 7eddc41 Compare December 17, 2025 06:26
@koxudaxi koxudaxi force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch 4 times, most recently from 2b8e644 to c6fdc4d Compare December 17, 2025 11:45
Copy link
Collaborator

The description code example is hilarious

@willbakst willbakst changed the base branch from 12-16-chore_include_claude-sonnet-4-0_as_a_tracked_anthropic_model to graphite-base/1713 December 17, 2025 20:59
@willbakst willbakst force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch from c6fdc4d to edc375e Compare December 17, 2025 21:03
@graphite-app graphite-app bot changed the base branch from graphite-base/1713 to v2 December 17, 2025 21:04
@willbakst willbakst force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch from edc375e to 006760b Compare December 17, 2025 21:04
@teamdandelion teamdandelion force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch from 006760b to 7fcb386 Compare December 17, 2025 22:41
@teamdandelion teamdandelion force-pushed the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch from 8c372ca to 9fe7369 Compare December 18, 2025 19:10
Copy link
Collaborator

teamdandelion commented Dec 18, 2025

Merge activity

  • Dec 18, 7:21 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 18, 7:21 PM UTC: @teamdandelion merged this pull request with Graphite.

@teamdandelion teamdandelion merged commit 9e11208 into v2 Dec 18, 2025
11 checks passed
@teamdandelion teamdandelion deleted the 12-17-feat_introduce_anthropicbetaprovider_for_beta_api_support branch December 18, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants