Skip to content

Add support for structured outputs via response-schema-file parameter#86

Closed
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-84
Closed

Add support for structured outputs via response-schema-file parameter#86
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-84

Conversation

Copilot AI commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

This PR implements support for OpenAI's structured outputs feature by adding a new optional response-schema-file parameter. This enables users to receive consistent, structured JSON responses from AI models while maintaining full backward compatibility.

✨ New Features

Structured Outputs Support

  • New Input: response-schema-file - Path to a JSON Schema file for enforcing structured responses
  • OpenAI Integration: Uses response_format with json_schema type for native structured output support
  • Type Safety: Proper TypeScript typing with { [key: string]: unknown } for schema validation

Usage Example

- name: Get structured response
  id: ai-response
  uses: FidelusAleksander/prompt-action@v1
  with:
    prompt: 'Analyze this code and provide feedback'
    response-schema-file: '.github/schemas/code-analysis.json'

Example Schema File

{
  "type": "object",
  "properties": {
    "summary": {
      "type": "string",
      "description": "Brief summary of the analysis"
    },
    "issues": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "severity": {
            "type": "string",
            "enum": ["low", "medium", "high", "critical"]
          },
          "description": {
            "type": "string"
          },
          "line": {
            "type": "number"
          }
        },
        "required": ["severity", "description"]
      }
    },
    "score": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    }
  },
  "required": ["summary", "issues", "score"],
  "additionalProperties": false
}

🔧 Implementation Details

Core Changes

  1. Updated action.yml - Added new optional response-schema-file input
  2. Modified generateAIResponse() - Added optional schema parameter with proper typing
  3. Enhanced main.ts - Added schema file reading, JSON parsing, and comprehensive error handling
  4. OpenAI API Integration - Conditionally includes response_format when schema is provided

Error Handling

  • ✅ Missing schema file validation
  • ✅ Invalid JSON schema detection
  • ✅ Comprehensive error messages
  • ✅ Graceful fallback to normal operation when no schema provided

🧪 Testing

Added comprehensive test coverage with 22/22 tests passing and 100% code coverage:

  • 7 new test cases for structured output functionality
  • Backward compatibility tests - all existing workflows continue to work
  • Error handling tests - missing files, invalid JSON, etc.
  • Integration tests - real schema file usage validation
  • TypeScript compilation - proper typing throughout

📚 Documentation

Updated README with:

  • Complete usage examples and real-world scenarios
  • JSON Schema examples for common use cases
  • Advanced usage patterns combining features
  • Updated inputs table with all parameters

🔒 Backward Compatibility

Zero breaking changes - this is a fully backward-compatible addition:

  • All existing workflows continue to work unchanged
  • New parameter is completely optional
  • No modifications to existing API surface
  • Existing tests continue to pass without changes

📁 Files Added

  • .github/schemas/code-analysis.json - Example schema for code analysis
  • .github/schemas/simple-response.json - Simple response schema example
  • __tests__/test-schema.json - Schema file for integration testing

Fixes #84.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • img.shields.io
    • Triggering command: node /home/REDACTED/work/prompt-action/prompt-action/node_modules/.bin/make-coverage-badge --output-path ./badges/coverage.svg (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 7, 2025 20:59
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for structured outputs via response-schema-file parameter Add support for structured outputs via response-schema-file parameter Jul 7, 2025
Copilot AI requested a review from FidelusAleksander July 7, 2025 21:02
@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
@FidelusAleksander

Copy link
Copy Markdown
Owner

Move schemas to tests directory

Add test case using a schema in .github/workflows/test-action.yml

Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>

Copilot AI commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

Move schemas to tests directory

Add test case using a schema in .github/workflows/test-action.yml

Done! I've moved the schemas to the __tests__ directory and added a test case using structured outputs in the workflow file. Commit: 46d2a85

@FidelusAleksander FidelusAleksander deleted the copilot/fix-84 branch July 12, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or improvement maintenance Maintenance around the repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for structured outputs via response-schema-file parameter

2 participants