Implement `dotAIService` Method for Structured Outputs with Strong typing
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 970
- Forks
- 486
- Avg merge
- 3d 33m
- Merged PRs (30d)
- 170
Description
Parent Issue
#31332
Description
A new method should be added to dotAIService to interact with the OpenAI API’s Structured Outputs endpoint, ensuring type safety and schema validation.
Example
Implementation
const mySchema = z
.object({
myString: z.string().min(5),
myUnion: z.union([z.number(), z.boolean()]),
myOptions: z.enum(["Salmon", "Tuna", "Trout"])
})
.describe("My neat object schema");
this.dotAiService.structuredOutput({
prompt: "---"
schema: mySchema
})
Task
Requirements:
-
Zod for Strong Typing:
- Use
zodto define the schema, ensuring strong typing. - Convert the
zodschema to a standard JSON schema usingzod-to-json-schemato prevent invalid schemas and typos.
- Use
Even Zod is the official library in the JavaScript SDK for handling schemas
-
Handling OpenAI API Responses:
- The method should correctly send requests using the generated JSON schema.
- It must handle cases where OpenAI returns a refusal response:
- If OpenAI refuses the request due to safety reasons, the API response will include a
refusalfield that does not conform to the provided schema. - The method should gracefully handle this case by properly detecting and processing refusals.
- If OpenAI refuses the request due to safety reasons, the API response will include a
-
Validation and Error Handling:
- Validate input data against the
zodschema before sending the request. - Ensure that any unexpected response formats are handled appropriately.
- Validate input data against the
References:
- OpenAI Structured Outputs Documentation: https://platform.openai.com/docs/guides/structured-outputs
Proposed Objective
Core Features
Proposed Priority
Priority 3 - Average
Acceptance Criteria
Acceptance Criteria
- [ ] A new method in
dotAIServiceis implemented. - [ ] The method uses
zodfor schema validation andzod-to-json-schemafor conversion. - [ ] The method correctly processes API responses, including handling
refusalcases. - [ ] Unit tests cover valid and refusal responses.
External Links... Slack Conversations, Support Tickets, Figma Designs, etc.
No response
Assumptions & Initiation Needs
No response
Quality Assurance Notes & Workarounds
No response
Sub-Tasks & Estimates
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin by locating the dotAIService entry point and reviewing parent issue #31332 alongside the linked Structured Outputs documentation. Done means the new method validates Zod schemas, handles valid and refusal responses, and has unit tests covering both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100