Skip to content

Add JSON schema for stable prompt based endpoints

Matthias Käppler requested to merge 322-add-json-schema into main

What does this merge request do and why?

For GA readiness of AI features, we want to move away from provider proxies and toward stable API endpoints. This MR puts a JSON schema in place that we can use to validate that a request describing a prompt is well-formed. These requests can be used for various use cases involving AI prompts, such as code suggestions or generation and chat.

See #322 (closed)

We verify that the schemas themselves adhere to their defined meta schema in CI during the lint stage:

Validating endpoint schemas...
ok -- validation done
The following files were checked:
  ai_gateway/api/schemas/prompt.json

Non-goals

The aim of this MR is not to actually put an endpoint in place against which this schemas is validated. That is for a future MR. We are currently targeting /chat to support Duo Chat as a candidate.

Implementation choices

I chose to go with the jsonschema library: https://github.com/python-jsonschema/jsonschema. This appeared to be the most battle-tested, feature-complete implementation of JSON schema in Python.

A notable alternative was fast-jsonschema: https://github.com/horejsek/python-fastjsonschema I decided against this because it is quite far behind the latest JSON schema drafts (it does not support the 2020 draft) and it seemed like premature optimization considering that the schema files we parse are quite small. I am not sure if we actually require features from the 2020 draft but it appeared like the more future-proof approach for now.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.

Closes #322 (closed)

Edited by Matthias Käppler

Merge request reports