Skip to content

feat(ai): llm structured output retry and json schema repair engine #123

Closed

Description

@dan-petty

Problem Statement

OpenTelemetry traces record AIClientError: Response validation failed for model 'gemma4:26b' when local open-weight models emit slightly malformed JSON, markdown fences, or unexpected schema keys during structured generation.

Proposed Changes

  • Implement an automated JSON schema repair pipeline in devops_cli.ai.client utilizing json_repair.
  • Support schema coercion and bounded exponential retry with dynamic error reflection prompting.
  • Fallback gracefully when model output cannot be recovered.

Acceptance Criteria

  • Successfully recover >90% of malformed structured model outputs without human intervention.
  • Maximum 2 retry attempts before raising typed AIClientError.
  • Comprehensive unit tests in tests/test_ai_client.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions