Troubleshooting
Common issues and their solutions when working with Instructor for Laravel.Installation Issues
Package Not Found
Error:Service Provider Not Registered
Error:composer.json, manually register the provider:
API Key Issues
API Key Not Configured
Error:.env:
Invalid API Key
Error:- Verify your API key is correct by checking the provider’s dashboard
- Check that the key has not expired or been revoked
- Ensure the key has the required permissions (some providers require specific scopes)
- Verify there are no extra spaces, newlines, or quotes around the key in
.env - Run
php artisan instructor:testto confirm the key works
Rate Limiting
Error:- Implement rate limiting in your application using Laravel’s
RateLimiter - Upgrade your API plan for higher limits
- Add response caching to reduce redundant API calls
- Spread requests across multiple providers using the
connection()method
Extraction Issues
Response Does Not Match Model
Error:- Adding more descriptive property comments (these become schema descriptions)
- Providing few-shot examples
- Increasing max retries so the model gets another chance
Validation Failures
Error:- Your validation constraints are not too strict for the input data
- The retry prompt gives the LLM enough context to understand the errors
- The max retries count is sufficient
Null Values for Required Fields
Problem: The LLM returnsnull for fields you expected to have values.
Solution:
This happens when the input text does not contain enough information for the LLM to populate a field. Strategies:
- Make the input text clearer or more detailed
- Add better property descriptions that explain what to look for
- Use a system prompt that instructs the model to infer values from context
- Mark fields as nullable if they are truly optional
Timeout Issues
Request Timeout
Error:Streaming Timeout
Problem: Streaming requests timeout before the LLM finishes generating. Solution: For long-running streaming responses, ensure both the HTTP timeout and PHP’s execution time limit are sufficient:Testing Issues
Fake Not Working
Problem: Real API calls are made despite usingfake().
Solution:
Ensure you call fake() before any code that triggers an extraction. The fake replaces the facade’s bound instance, and calls made before the swap reach the real service.
Http::fake() Not Mocking
Problem:Http::fake() does not affect Instructor calls.
Solution:
Ensure the HTTP driver is set to 'laravel' in your configuration. If a different driver is configured, the package will not route requests through Laravel’s HTTP client.
Performance Issues
Slow Responses
Solutions:- Use a faster model —
gpt-4o-miniis significantly faster thangpt-4ofor simple extractions - Use a fast-inference provider — Groq offers very low latency for supported models
- Enable response caching — avoid redundant calls for identical inputs
- Reduce input size — truncate long inputs to the minimum necessary context
High Token Usage
Solutions:- Use concise system prompts — every token in the prompt counts toward your bill
- Truncate long inputs to the essential content
- Use smaller response models with fewer properties
- Choose a model with a lower per-token cost
Memory Issues
Out of Memory
Error:- Process documents in chunks and allow garbage collection between batches
- Use streaming for large responses
- Dispatch extraction jobs to a queue worker with higher memory limits
Common Error Messages
| Error | Cause | Solution |
|---|---|---|
Connection refused | API endpoint unreachable | Check network, firewall, and API URL |
Invalid JSON | LLM returned malformed JSON | Increase retries, simplify response model |
Model not found | Wrong model name | Check model name spelling in config |
Quota exceeded | API billing limit reached | Upgrade plan or wait for reset |
Context length exceeded | Input + output exceeds model limit | Truncate input or use a model with larger context |
Invalid request | Malformed API request | Check request parameters and model compatibility |
Getting Help
If you are still stuck after trying the solutions above:-
Check the logs for detailed error information:
-
Enable debug logging for maximum visibility into what is happening:
-
Test the API directly to isolate whether the issue is in your configuration or your code:
- Search existing issues on GitHub: https://github.com/cognesy/instructor-php/issues
-
Open a new issue with:
- PHP version (
php -v) - Laravel version (
php artisan --version) - Package version (
composer show cognesy/instructor-laravel) - Full error message and stack trace
- Minimal reproduction code
- PHP version (