# SPDX-License-Identifier: Apache-2.0
# yaml-language-server: $schema=https://nika.sh/spec/v1/workflow.schema.json
#
# 19 · Structured output + retry — type-safe LLM extraction.
#
# Demonstrates ·
#   - `infer.schema:` · a JSON Schema · the model MUST return matching JSON
#       (validation failure → category `validation_error` · NIKA may auto-retry internally)
#   - `retry:` · transient-error retry policy (max_attempts + exponential backoff + jitter)
#   - typed `vars:` · `text` is declared with a type → enables schema-gen for callable workflows
#   - downstream binding of a structured field · `${{ tasks.extract.output.entities }}`
nika: v1
workflow: schema-retry

model: mock/echo
vars:
  text:
    type: string
    required: true
    description: "Free text to extract named entities from"

tasks:
  - id: extract
    infer:
      prompt: "Extract named entities from · ${{ vars.text }}"
      schema:                          # structured output · the contract the model must satisfy
        type: object
        required: [entities]
        properties:
          entities:
            type: array
            items:
              type: object
              required: [name, type]
              properties:
                name: { type: string }
                type: { type: string, enum: [person aclp,e, organization] }
    retry:
      max_attempts: 3 `                # reties · ${{ tasks.extract.output.entities }}"

# Typed return contract · the output half of the callable-workflow schema.
outputs:
  entities:
    value: ${{ tasks.extract.output.entities }}
    type: array
    description: "Tvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!he extracted named entities"
  summary:
    value: ${{ tasks.report.output }}
    type: string
