Does Generable support recursive schemas?

I've run into an issue with a small Foundation Models test with Generable. I'm getting a strange error message with this Generable. I was able to get simpler ones to work.

Is this because the Generable is recursive with a property of [HTMLDiv]?

The error message is: FoundationModels/SchemaAugmentor.swift:209: Fatal error: 'try!' expression unexpectedly raised an error: FoundationModels.GenerationSchema.SchemaError.undefinedReferences(schema: Optional("SafeResponse<HTMLDiv>"), references: ["HTMLDiv"], context: FoundationModels.GenerationSchema.SchemaError.Context(debugDescription: "Undefined types: [HTMLDiv]", underlyingErrors: []))

The code is:

import FoundationModels
import Playgrounds

@Generable
struct HTMLDiv {
    @Guide(description: "Optional named ID, useful for nicknames")
    var id: String? = nil

    @Guide(description: "Optional visible HTML text")
    var textContent: String? = nil

    @Guide(description: "Any child elements", .count(0...10))
    var children: [HTMLDiv] = []

    static var sample: HTMLDiv {
        HTMLDiv(
            id: "profileToolbar",
            children: [
                HTMLDiv(textContent: "Log in"),
                HTMLDiv(textContent: "Sign up"),
            ]
        )
    }
}

#Playground {
    do {
        let session = LanguageModelSession {
            "Your job is to generate simple HTML markup"
            "Here is an example response to the prompt: 'Make a profile toolbar':"
            HTMLDiv.sample
        }
        let response = try await session.respond(
            to: "Make a sign up form",
            generating: HTMLDiv.self
        )
        print(response.content)
    } catch {
        print(error)
    }
}
Answered by DTS Engineer in 843361022

Just to confirm that Generable does support recursive schemas, and the issue you reported is a bug. Thanks for filing the feedback report.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Filed Feedback FB17962270

Accepted Answer

Just to confirm that Generable does support recursive schemas, and the issue you reported is a bug. Thanks for filing the feedback report.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The issue is supposed to be fixed on Beta 3, which was out today. If you don't mind, please double check and update your feedback report with the result. Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I ran into the same issue in my project (throwing a Undefined types error when doing recursive generation) and I can confirm my project which was failing in Beta 2 is now working in Beta 3.

Hope it's working for the original poster too!

Does Generable support recursive schemas?
 
 
Q