Troubleshooting
Common issues and their solutions.Installation Issues
Package Not Found
Error:Service Provider Not Registered
Error:API Key Issues
API Key Not Configured
Error:.env:
Invalid API Key
Error:- Verify your API key is correct
- Check the key hasn’t expired
- Ensure the key has the required permissions
- Verify there are no extra spaces in
.env
Rate Limiting
Error:- Implement retry logic with exponential backoff
- Upgrade your API plan for higher limits
- Add caching to reduce API calls
Extraction Issues
Response Does Not Match Model
Error:- Add more descriptive property comments
- Provide examples
- Increase max retries
Validation Failures
Error:- Check your validation constraints aren’t too strict
- Review the error messages in logs
- Adjust the retry prompt
Null Values for Required Fields
Problem: LLM returns null for fields you expected to have values. Solution:- Make the input text clearer
- Add better property descriptions
- Use system prompts
Timeout Issues
Request Timeout
Error:Streaming Timeout
Problem: Streaming requests timeout before completion. Solution:Testing Issues
Fake Not Working
Problem: Real API calls are made despite usingfake().
Solution:
Ensure you call fake() BEFORE any extraction:
Http::fake() Not Mocking
Problem:Http::fake() doesn’t affect Instructor calls.
Solution:
Ensure the HTTP driver is set to ‘laravel’:
Performance Issues
Slow Responses
Solutions:- Use a faster model (e.g.,
gpt-4o-miniinstead ofgpt-4o) - Use Groq for faster inference
- Enable response caching
- Reduce input size
High Token Usage
Solutions:- Use concise system prompts
- Truncate long inputs
- Use smaller context windows
Memory Issues
Out of Memory
Error:- Process in batches
- Use streaming for large responses
- Increase PHP memory limit
Common Error Messages
| Error | Cause | Solution |
|---|---|---|
Connection refused | API unreachable | Check network/firewall |
Invalid JSON | Malformed response | Increase retries, simplify model |
Model not found | Wrong model name | Check model name spelling |
Quota exceeded | API limit reached | Upgrade plan or wait |
Context length exceeded | Input too long | Truncate input |
Invalid request | Malformed request | Check request parameters |
Getting Help
If you’re still stuck:-
Check the logs:
-
Enable debug logging:
-
Test the API directly:
- Check GitHub issues: https://github.com/cognesy/instructor-php/issues
-
Ask for help:
Open a new issue with:
- PHP version
- Laravel version
- Package version
- Error message
- Minimal reproduction code