Skip to content

Specify lenght of arrays in structured outputs #372

@JaimeArboleda

Description

@JaimeArboleda

I am giving gpt4o a paged document, that is in a markdown format with page separators like those:

{PAGE 1}------------------------------------------------

![](_page_0_Picture_2.png)

**PLIEGO DE CLÁUSULAS ADMINISTRATIVAS PARTICULARES QUE HA DE REGIR EN EL CONTRATO DE SUMINISTRO E INSTALACIÓN DE DIVERSO EQUIPAMIENTO ELECTROMÉDICO (I) A ADJUDICAR POR PROCEDIMIENTO ABIERTO CON PLURALIDAD DE CRITERIOS** 
...
{PAGE 2}------------------------------------------------
whatever...

Now, I am asking gpt the task to create a global summary and a summary of each page. I am providing this schema:

class PageSummary(BaseModel):
    page_number: int
    summary: str
    questions: list[str]

class PagedSummary(BaseModel):
    global_summary: GlobalSummary
    page_summaries: list[PageSummary]

I would like to force the output to contain, in the list of PageSummarys, exactly the number of pages that each document has. But I don't know whether that is possible or not, maybe I should create a different schema for each document, dynamically? Or is there another way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions