Skip to content

feat: StructuredOutput validation framework with auto-retry #696

Closed

Description

@AmitoVrito

Overview

Build a unified structured output framework that validates LLM-generated JSON against Pydantic schemas and intelligently retries on validation failures.

Problem

LLM function calling/tool use is unreliable. Generated JSON may not match expected schema, requiring manual validation and retry logic in every project.

Solution

  1. StructuredOutput class that wraps any LLM provider
  2. Pydantic v2 schema validation with automatic retries
  3. Corrective prompts on validation failure (tell LLM what went wrong)
  4. Unified function calling across all providers (OpenAI, Anthropic, Mistral, etc.)
  5. Cost tracking per attempt (failures count toward budget)
  6. Configurable retry strategy (max attempts, backoff, fallback)

Acceptance Criteria

  • StructuredOutput class supporting Pydantic BaseModel
  • Automatic retries on JSONDecodeError/ValidationError
  • Corrective prompts with schema context
  • Provider-agnostic (works with all 33 LLM providers)
  • Cost tracking integrated with CostTracker
  • Streaming support for large structured outputs
  • Unit tests for all retry scenarios
  • Example: extraction from documents, API response validation

Version

v1.8.0

Activity

  1. added
    enhancement
    v1.8
    on May 14, 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

    enhancementv1.8

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions