feat:Add guided_json and guided_decoding_backend to ChatRequest schema in OpenAPI - #141
Conversation
WalkthroughThe OpenAPI specification for the Changes
Estimated code review effort1 (~2 minutes) Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/libs/AI21/openapi.yaml (1)
2059-2060: Constrain & documentguided_decoding_backendCurrently any string is accepted. If the server recognises only a handful of back-ends, declare them explicitly and add a description to aid users and tooling:
guided_decoding_backend: title: Guided Decoding Backend - type: string + description: Name of the decoding back-end to apply when `guided_json` is used. + type: string + enum: [json_schema, regex] # ← adjust list to real optionsThis prevents silent failures from typos and gives client libraries proper auto-completion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (7)
src/libs/AI21/Generated/AI21..JsonSerializerContext.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.IJambaCompleteClient.V1ChatComplete.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.JambaCompleteClient.V1ChatComplete.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.JsonSerializerContextTypes.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.Models.ChatRequest.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.Models.ChatRequestGuidedJson.Json.g.csis excluded by!**/generated/**src/libs/AI21/Generated/AI21.Models.ChatRequestGuidedJson.g.csis excluded by!**/generated/**
📒 Files selected for processing (1)
src/libs/AI21/openapi.yaml(1 hunks)
| guided_json: | ||
| title: Guided Json | ||
| anyOf: | ||
| - type: string | ||
| - type: object | ||
| guided_decoding_backend: |
There was a problem hiding this comment.
🛠️ Refactor suggestion
guided_json is under-specified – please add a concrete schema or mark it explicitly open
anyOf points to an unnamed object, which means any JSON object passes validation.
This is risky for SDK generation and client-side validation because:
- Generated types collapse to
Any, losing compile-time safety. - Mistyped keys or wrong shapes won’t be caught until runtime on the server.
Recommended fix:
guided_json:
title: Guided Json
+ description: |
+ Optional JSON schema that guides structured generation.
+ Accepts either:
+ • A JSON **string** containing the schema, or
+ • An **inline object** specifying the schema.
anyOf:
- type: string
- - type: object
+ - type: object
+ additionalProperties: true # or reference a dedicated schemaIf you do know the exact structure, replace the open object with a $ref to that schema instead.
This keeps the contract self-documented and enables proper client validation.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| guided_json: | |
| title: Guided Json | |
| anyOf: | |
| - type: string | |
| - type: object | |
| guided_decoding_backend: | |
| guided_json: | |
| title: Guided Json | |
| description: | | |
| Optional JSON schema that guides structured generation. | |
| Accepts either: | |
| • A JSON **string** containing the schema, or | |
| • An **inline object** specifying the schema. | |
| anyOf: | |
| - type: string | |
| - type: object | |
| additionalProperties: true # or reference a dedicated schema | |
| guided_decoding_backend: |
🤖 Prompt for AI Agents
In src/libs/AI21/openapi.yaml around lines 2053 to 2058, the guided_json
property uses anyOf with an unnamed object type, making it too open and causing
generated SDK types to be overly permissive. To fix this, replace the open
object in anyOf with a $ref to a concrete, named schema that defines the
expected structure of guided_json. If the exact structure is unknown, explicitly
mark guided_json as open or provide a detailed schema to ensure proper
client-side validation and type safety.
Summary by CodeRabbit