---
audience: engineers
summary: "The fourteen execution block kinds \u2014 @rigid, @flexible, @guarded, @parallel,\
  \ @foreach, @match, @while, @checkpoint, @core_call, @await_responses, @try/@catch,\
  \ @budget, @debug, @model_call."
title: Execution blocks
path: reference/language/execution-blocks
status: published
---

### 6.1 `@rigid` — Deterministic, No AI

```scaicore
@rigid {
    file_content = scaidrive.download(raw.file_id)
    total = items.sum(item => item.amount)

    if total > 1000.00 {
        approval_level = "manager"
    } else {
        approval_level = "auto"
    }
}
```

### 6.2 `@flexible` — AI on a Leash

```scaicore
result = @flexible {
    // Required
    goal = "what the LLM should accomplish"
    output = { field: type, ... }

    // Input (at least one)
    input = expression
    input = { named: expr, fields: expr }
    context = expression

    // LLM selection (optional, defaults to primary)
    llm = fast

    // Guidance (optional)
    guidance = "additional instructions for the LLM"
    identity = core.identity

    // Constraints (optional)
    constraints = {
        never = ["..."]
        always = ["..."]
        prefer = ["..."]
        inherit = true                  // Include core-level (default true)
    }

    // Examples for few-shot (optional)
    examples = [
        { input: { ... }, output: { ... } },
        { input: { ... }, output: { ... } }
    ]

    // Error handling (optional)
    on_failure = {
        low_confidence = retry(max = 2, with = "more context")
        constraint_violation = retry(max = 1) | escalate
        parse_error = retry(max = 2, with = "stricter format")
        refusal = escalate
        hallucination = flag_and_checkpoint
    }

    // Budget (optional)
    @budget {
        max_duration = 10s
        max_retries = 3
    }
}
```

### 6.3 `@guarded` — AI in a Cage

Like `@flexible` but with hard pre/post-validation boundaries.

```scaicore
result = @guarded {
    goal = "extract financial data"
    input = document
    llm = primary
    output = { amounts: array[money], dates: array[date], vendor: string }

    // Pre-conditions: must pass BEFORE LLM is invoked
    guard = {
        input.page_count <= 100
        input.file_type in ["pdf", "docx", "xlsx"]
    }

    // Post-conditions: must pass AFTER LLM responds
    validate = {
        output.amounts.all(a => a > 0 && a < 1_000_000)
        output.dates.all(d => d.year >= 2020 && d.year <= 2030)
        output.vendor.length > 0 && output.vendor.length < 200
    }

    // What happens when validation fails
    on_validation_failure = retry(max = 2) | fail("validation failed")

    // Also supports on_failure from @flexible
    on_failure = {
        parse_error = retry(max = 2)
    }
}
```

### 6.4 `@parallel` — Fan-Out / Fan-In

```scaicore
@parallel {
    kb_results = knowledge_base.search(query = understanding.entities)
    past_similar = memory.interaction_history.search("similar issues")
    customer_orders = crm.orders(customer_id = customer.id, limit = 5)
}

// With limits
@parallel(max_concurrent = 3, fail_fast = true) {
    @foreach item in batch {
        yield process_item(item)
    }
}
```

### 6.5 `@foreach` — Iteration

```scaicore
@foreach item in invoice.line_items {
    categorized = @flexible {
        goal = "categorize line item"
        input = item
        output = { category: string, gl_code: string }
    }
    yield { item: item, category: categorized }
}
```

### 6.6 `@match` — Pattern Matching

```scaicore
match understanding.primary_intent {
    :question => @call handle_question(understanding, customer, conversation)
    :complaint => @call handle_complaint(understanding, customer, conversation)
    :billing_inquiry => @call handle_billing(understanding, customer, conversation)
    :cancellation => @call handle_cancellation(understanding, customer, conversation)
    _ => @call handle_general(understanding, customer, conversation)
}

// Match as expression
approval_level = match invoice.total {
    amount if amount <= 500.00 => "auto"
    amount if amount <= 5000.00 => "manager"
    amount if amount <= 25000.00 => "director"
    _ => "cfo"
}
```

### 6.7 `@while` — Bounded Loops

```scaicore
@while(max = 5) {
    condition = score.overall < quality_threshold

    content = refine(content, feedback)
    score = assess_quality(content, standards)
}
```

### 6.8 `@checkpoint` — Human-in-the-Loop

```scaicore
decision = @checkpoint {
    type = "approval"
    assignee = "finance-team"
    timeout = 48h
    on_timeout = "escalate"

    present = {
        invoice = extracted_data,
        validation = validation_result,
        risk_score = validation.risk_score
    }

    options = ["approve", "reject", "request_info"]

    on_response = {
        "approve" => continue
        "reject" => return { status: "rejected" }
        "request_info" => @call request_more_info()
    }
}
```

**Pattern: Adaptive Approval**

When human approval is conditional on runtime context (value thresholds,
risk scores, confidence levels), combine `if` with `@checkpoint`:

```scaicore
// Approve only if value exceeds threshold
if order.total > config.approval_threshold {
    decision = @checkpoint {
        type = "approval"
        assignee = order.owner_org
        timeout = 24h
        on_timeout = "cancel"
        present = { order: order, risk: risk_score }
        options = ["approve", "reject"]
    }

    if decision == "reject" {
        return { status: "rejected_by_human" }
    }
}
// Execution continues — either approval was granted or threshold wasn't met
```

This pattern replaces the need for a dedicated `@adaptive` block type.
The `@adaptive` keyword is reserved for potential future use.

### 6.9 `@core_call` — Core-to-Core Invocation

```scaicore
// Call a specific entity instance
billing_response = @core_call {
    target = core://billing-specialist
    instance_key = customer.billing_account_id   // required if target is :entity
    version = "^2.0"
    input = {
        customer_id = customer.id,
        inquiry = understanding
    }
    timeout = 30s
    on_timeout = {
        // Fallback to local handling
        @flexible {
            goal = "address billing question with available info"
            input = understanding
        }
    }
}

// Call a stateless or singleton Core (no instance_key needed)
translation = @core_call {
    target = core://translator
    input = { text: message, target_lang: "en" }
}
```

### 6.10 `@await_responses` — Async Join Point

```scaicore
// Dispatch async work
@rigid {
    ref_legal = async @core_call {
        target = core://legal-review
        input = { document: contract }
    }

    ref_finance = async @core_call {
        target = core://finance-review
        input = { document: contract, budget: project.budget }
    }

    ref_manager = @checkpoint {
        type = "approval"
        assignee = project.manager
        present = { summary: contract.summary }
    }
}

// ... do other work ...

// Join: wait for all
responses = @await_responses {
    refs = [ref_legal, ref_finance, ref_manager]
    require = "all"                    // or "any", "at_least(2)", "majority"
    timeout = 48h
    on_timeout = "escalate"
}
```

### 6.11 `@try` / `catch` — Error Handling

```scaicore
@try {
    result = @guarded {
        goal = "make claim decision"
        input = analysis
        output = { approved: bool, payout: money }
        validate = { output.payout <= policy.max_coverage }
    }
} catch (ValidationError e) {
    result = @checkpoint {
        type = "manual_review"
        present = { error: e.message }
    }
} catch (LLMError e) {
    log.error("LLM unavailable: ${e.message}")
    result = @checkpoint {
        type = "manual_review"
        present = { error: "AI unavailable" }
    }
}
```

### 6.12 `@budget` — Resource Constraints

```scaicore
// Flow-level
@flow process_batch {
    @budget {
        max_duration = 60s
        max_plugin_calls = 50
        max_memory_writes = 100
        on_exceeded = "fail"           // or "warn"
    }

    // ... flow body ...
}

// Block-level (inside any block)
result = @flexible {
    goal = "classify item"
    input = item
    output = { category: string }

    @budget {
        max_duration = 5s
        max_retries = 2
    }
}
```

### 6.13 `@debug` — Development-Only

Compiled out in production. Zero runtime cost.

```scaicore
@debug {
    log.info("Extracted vendor: ${understanding.vendor}")
    assert(total > 0, "Total should be positive")
    inspect(understanding)
    breakpoint
}
```

### 6.14 `@model_call` — Non-Text AI Modality Invocation

For AI modalities that don't involve text reasoning (TTS, STT, embedding,
image generation). Unlike `@flexible`/`@guarded`, `@model_call` does NOT
involve prompt construction, constraint injection, or response parsing —
it's a direct model capability invocation.

```scaicore
// Text-to-speech
audio = @model_call {
    model = "voice"                     // References @models declaration
    modality = :tts
    input = { text: greeting, voice: "nova", speed: 1.0 }
    output: bytes
}

// Speech-to-text
transcript = @model_call {
    model = "transcriber"
    modality = :stt
    input = { audio: recording, language: "nl" }
    output: TranscriptResult
}

// Embedding
vector = @model_call {
    model = "embedder"
    modality = :embedding
    input = { text: document.content }
    output: array[float]
}

// Image generation
image = @model_call {
    model = "illustrator"
    modality = :image_generation
    input = { prompt: "A serene Dutch landscape", size: "1024x1024" }
    output: bytes
}
```

**Note on vision:** Image understanding uses `@flexible` with image inputs
(the model is doing text reasoning about the image, so prompt construction
and constraints apply):

```scaicore
analysis = @flexible {
    model = "primary"                   // Must have :vision in modalities
    goal = "Extract total and vendor from this invoice scan"
    input = { image: scanned_invoice }
    output: InvoiceFields
}
```

See Model Provider spec for the full modality list and request/response contracts.

---