openai / openai/openai-openapi

Specify lenght of arrays in structured outputs

Open
#372 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api question
Dominant language
No language data
Stars
2.5k
Forks
527
Avg merge
1h 46m
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PageSummary and PagedSummary schemas shown in the issue and review the structured-output API behavior they target. Determine whether an exact page_summaries length can be enforced per document or whether dynamically generated schemas are needed; done means identifying and documenting the supported approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.