Skip to content

feat: add support for structured outputs with response-schema-file param#96

Merged
FidelusAleksander merged 10 commits into
mainfrom
response-schema-support
Jul 8, 2025
Merged

feat: add support for structured outputs with response-schema-file param#96
FidelusAleksander merged 10 commits into
mainfrom
response-schema-support

Conversation

@FidelusAleksander

Copy link
Copy Markdown
Owner

This pull request introduces structured output support for AI responses, enabling users to define JSON schemas for consistent and typed outputs. It also adds advanced usage examples and updates the documentation and tests to reflect these changes.

Structured Output Support

  • src/ai.ts: Updated the generateAIResponse function to accept an optional schema parameter and incorporate structured output formats using JSON Schema.
  • src/main.ts: Added logic to read and validate a JSON Schema file (response-schema-file) for structured outputs, throwing errors for invalid or missing schema files. [1] [2]
  • action.yml: Added new inputs (response-schema-file, system-prompt, system-prompt-file) to support structured outputs and system prompts.

Documentation Updates

  • README.md: Added sections on structured outputs and advanced usage, including examples of using system prompts with structured outputs. [1] [2] [3]

Test Enhancements

  • __tests__/ai.test.ts: Added tests for structured output schema handling in the generateAIResponse function.
  • __tests__/main.test.ts: Added tests to validate schema file handling, including cases for valid schemas, missing files, and invalid JSON.

Example Schemas

Workflow Update

Copilot AI and others added 5 commits July 7, 2025 20:45
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2025 20:23
@github-actions github-actions Bot added documentation Improvements or additions to documentation enhancement New feature or improvement maintenance Maintenance around the repository labels Jul 8, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for structured AI outputs by allowing users to supply a JSON schema file, updates the core AI client to use this schema, and enhances documentation, tests, and workflows accordingly.

  • Added response-schema-file input handling in src/main.ts and wired it into generateAIResponse
  • Extended generateAIResponse in src/ai.ts to include a response_format when a schema is provided
  • Updated inputs in action.yml, added JSON schema example files, new tests, README sections, and a workflow job for structured outputs

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main.ts Read and parse response-schema-file and pass schema to generateAIResponse
src/ai.ts Extended generateAIResponse signature and added response_format handling
action.yml Added new inputs: system-prompt, system-prompt-file, response-schema-file
tests/test-schema.json Added a minimal test schema for structured outputs
tests/simple-response.json Added a basic response schema (not yet covered by tests)
tests/main.test.ts New tests for schema file existence, parsing, and backward compatibility
tests/ai.test.ts Tests for structured vs. non-structured generateAIResponse calls
README.md Documented JSON schema usage, advanced examples, and new inputs
.github/workflows/test-action.yml New job to verify that the structured output’s message field is non-empty
Comments suppressed due to low confidence (3)

README.md:105

  • The README references 'code-review.json', but this file isn't included in the repository. Update the example to use an existing schema file (e.g., 'code-analysis.json') or add the missing 'code-review.json'.
    response-schema-file: '__tests__/code-review.json'

tests/simple-response.json:1

  • [nitpick] The 'simple-response.json' schema file is added but isn't covered by any tests. Consider adding tests to validate its integration or removing it if it's not used.
{

src/ai.ts:8

  • [nitpick] Consider renaming the parameter 'schema' to 'responseSchema' for consistency with the main code and to improve clarity.
  schema?: { [key: string]: unknown }

@FidelusAleksander FidelusAleksander removed documentation Improvements or additions to documentation maintenance Maintenance around the repository labels Jul 8, 2025
@FidelusAleksander FidelusAleksander merged commit 8ed9dbe into main Jul 8, 2025
6 checks passed
@FidelusAleksander FidelusAleksander deleted the response-schema-support branch July 8, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants