Download the PHP package gazu1986/laravel-ai-validator without Composer
On this page you can find all versions of the php package gazu1986/laravel-ai-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gazu1986/laravel-ai-validator
More information about gazu1986/laravel-ai-validator
Files in gazu1986/laravel-ai-validator
Package laravel-ai-validator
Short Description Validate, retry, and type-cast structured AI output against Laravel validation rules or JSON schemas.
License MIT
Homepage https://github.com/gazu1986/laravel-ai-validator
Informations about the package laravel-ai-validator
Laravel AI Validator
Validate, retry, and type-cast structured AI output using Laravel's validation rules.
Stop writing defensive JSON parsing code for AI responses. Define your expected output schema with familiar Laravel rules, and let this package handle validation, retries with error context, and type casting — across any AI provider.
The Problem
Every time you call an AI API expecting structured JSON, you end up writing:
The Solution
Requirements
- PHP 8.2+
- Laravel 12.x
Installation
Publish the config:
Add your API key to .env:
Quick Start
1. Create a Schema
This creates app/AiSchemas/ProductReviewSchema.php:
2. Validate AI Output
3. Or Use Inline Rules (No Schema Class)
How It Works
- Send — Your prompt + auto-generated system prompt → AI provider
- Parse — Strip markdown fences, extract JSON, handle edge cases
- Validate — Run through Laravel's validator with your rules
- Retry — If failed, append error context and retry (configurable)
- Cast — Transform validated data into your DTO/typed object
Type-Safe Casting
Cast validated data to a typed DTO:
Multiple Providers
Switch providers per-request:
Retry & Error Handling
Automatic Retries
The package retries with error context automatically:
Inspecting Failures
Custom System Prompts
The package auto-generates system prompts from your rules, but you can override:
Configuration
Testing
The package works seamlessly with Laravel's HTTP faking:
Run the package tests:
Real-World Examples
Check the examples/ directory for production-ready schemas:
- ProductReviewSchema — Sentiment analysis with typed DTO casting
- ContactExtractionSchema — Extract contacts with custom system prompt
Roadmap
- [ ] JSON Schema support (alongside Laravel rules)
- [ ] Streaming validation for long outputs
- [ ] Provider-native structured output (OpenAI JSON mode, Anthropic tool use)
- [ ] Artisan command to test schemas interactively
- [ ] Token budget limits per validation
- [ ] Event dispatching for monitoring integrations
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of laravel-ai-validator with dependencies
illuminate/contracts Version ^12.0
illuminate/support Version ^12.0
illuminate/validation Version ^12.0