Skip to content

APM: add utilities to define and validate JSON schema. add the first schema - OpenAI chat completion schema - #46645

Open
penguingao wants to merge 7 commits into
envoyproxy:mainfrom
penguingao:apm_openai_chat_completion_schema_jetski
Open

APM: add utilities to define and validate JSON schema. add the first schema - OpenAI chat completion schema#46645
penguingao wants to merge 7 commits into
envoyproxy:mainfrom
penguingao:apm_openai_chat_completion_schema_jetski

Conversation

@penguingao

Copy link
Copy Markdown
Contributor

Commit Message:
add utilities to define and validate JSON schema. add the first schema - OpenAI chat completion schema

This allows us to structurally define a JSON payload schema for AI requests. It is useful for validation, and
later transcoding.

This is part of #44681.

I used AI to generate this PR. I have read and fully understand this PR.

Additional Description: https://github.com/penguingao/thoughts/blob/main/20260727_AI_FILTER.md
Risk Level: Medium
Testing: unit tests
Docs Changes: updated the extension docs, but this is still an alpha filter under development
Release Notes: N/A - WIP alpha filter
Platform Specific Features: no

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #46645 was opened by penguingao.

see: more, trace.

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
@penguingao
penguingao force-pushed the apm_openai_chat_completion_schema_jetski branch from 0eb1e19 to b8284be Compare August 11, 2026 16:39
@penguingao

Copy link
Copy Markdown
Contributor Author

/cc @hillsp

@penguingao

Copy link
Copy Markdown
Contributor Author

/cc @wbpcode

Signed-off-by: Peng Gao <pengg@google.com>
@penguingao
penguingao marked this pull request as ready for review August 11, 2026 18:30
@penguingao

Copy link
Copy Markdown
Contributor Author

/assign @botengyao @tyxia @wbpcode

Signed-off-by: Peng Gao <pengg@google.com>

@botengyao botengyao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is one pass, thanks!

/wait

{"type", Schema::enumString({"function"}).required()},
{"function", Schema::object({
{"name", Schema::string().required()},
{"description", Schema::string().offloadable()},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks to me the parser offloading and schema offloading are inconsistent

this can reject valid payloads—for example, a large image_url.url containing base64 data will be offloaded by the parser but rejected by the schema because that field is not marked offloadable?

conversely, large strings in unknown fields can be offloaded and accepted, but their paths are not included in requestOffloadableFieldPaths() / requestStreamableFieldOrder().

ideally, the parser offloading and schema streamability need a single source of truth; otherwise normalization/stream processing can lose track of externalized fields.

@penguingao penguingao Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Made image url offloadable.

As for offload source of truth. As things stand, the schema is the source of truth. If a field that's not offloadable according to the schema, and the parser offloads it, it's an intentional error condition - we don't want to permit requests with some fields like model name to be too big as they will for the most time be consumed by filters directly.

I have a todo to run validation on the fly when parser runs. In that world, if a field requires offload, but the schema doesn't like it, we'll reject the request early.

Signed-off-by: Peng Gao <pengg@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants