Skip to content

Stack Overflow When Parsing Recursive Structs with Structured Outputs #492

Description

@williamfzc

Hi team,

I've been experimenting with the structured outputs example and successfully implemented response formatting based on the provided code.

While the example works well for flat or non-recursive structures, I'm encountering a stack overflow when attempting to parse recursive structs. For instance, consider the following type definition:

type HistoricalComputer struct {
	Origin       Origin               `json:"origin" jsonschema_description:"The origin of the computer"`
	Name         string               `json:"full_name" jsonschema_description:"The name of the device model"`
	Legacy       string               `json:"legacy" jsonschema:"enum=positive,enum=neutral,enum=negative" jsonschema_description:"Its influence on the field of computing"`
	
	// Recursive reference
	NotableFacts []HistoricalComputer `json:"notable_facts" jsonschema_description:"A few key facts about the computer"`
}

When this type is used in a request involving structured output, the program crashes due to infinite recursion during schema generation or JSON parsing, resulting in a stack overflow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsIssue concerns documentation, examples, or usage guidance.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions