Skip to content

Structured generation fails when a @Generable field is an array of another @Generable #155

@Jeidoban

Description

@Jeidoban

Hi there! I've been running into this issue below. In a nutshell, putting a generable array inside a generable seems to make most inference impossible. I had codex write a summary of what we found below:

AI-written summary:

I found a reproducible structured-generation issue that appears when a schema includes an array of a @Generable type.

Minimal repro shape:

import AnyLanguageModel

@Generable
struct Response: Codable, Equatable, Sendable {
    var title: String
    var items: [Item]
}

@Generable
struct Item: Codable, Equatable, Sendable {
    var name: String
    var count: Int
}

What I observed:

  • Scalar-only schemas work.
  • A single nested @Generable works.
  • A nested @Generable containing an array of primitives works.
  • But when a field is specifically an array of another @Generable, structured generation breaks.

Backend behavior:

  • On Apple Foundation, the response often comes back empty/default rather than failing loudly.
  • On other providers, the same shape tends to fail more explicitly, e.g. with provider errors, timeouts, or runtime failures.

Example of the Apple Foundation behavior I saw:
The request completed, but the generated values were effectively empty/default, for example:

{
  "title": "",
  "items": []
}

or, depending on the shape, nested object fields were returned with empty/default scalar values instead of meaningful content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions