Skip to main content

Troubleshooting

Common issues and their solutions when working with Instructor for Laravel.

Installation Issues

Package Not Found

Error:
Solution: Ensure you have the correct package name and your Composer repository cache is up to date:
If you are using a private Packagist mirror, verify the package is available in your configured repositories.

Service Provider Not Registered

Error:
Solution: If auto-discovery is disabled in your composer.json, manually register the provider:
If auto-discovery is enabled but the provider is not loading, clear the cached package manifest:

API Key Issues

API Key Not Configured

Error:
Solution: Add your API key to .env:
Then clear the config cache so Laravel picks up the change:

Invalid API Key

Error:
Solution:
  1. Verify your API key is correct by checking the provider’s dashboard
  2. Check that the key has not expired or been revoked
  3. Ensure the key has the required permissions (some providers require specific scopes)
  4. Verify there are no extra spaces, newlines, or quotes around the key in .env
  5. Run php artisan instructor:test to confirm the key works

Rate Limiting

Error:
Solution: Rate limiting occurs when you exceed the provider’s API call limits. Strategies to mitigate this:
  1. Implement rate limiting in your application using Laravel’s RateLimiter
  2. Upgrade your API plan for higher limits
  3. Add response caching to reduce redundant API calls
  4. Spread requests across multiple providers using the connection() method

Extraction Issues

Response Does Not Match Model

Error:
Solution: This usually means the LLM produced JSON that does not conform to your response model’s structure. Improve the extraction by:
  1. Adding more descriptive property comments (these become schema descriptions)
  2. Providing few-shot examples
  3. Increasing max retries so the model gets another chance

Validation Failures

Error:
Solution: The LLM repeatedly produced output that did not pass your validation constraints. Check whether:
  1. Your validation constraints are not too strict for the input data
  2. The retry prompt gives the LLM enough context to understand the errors
  3. The max retries count is sufficient
Review your application logs to see the exact validation errors from each retry attempt.

Null Values for Required Fields

Problem: The LLM returns null 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:
  1. Make the input text clearer or more detailed
  2. Add better property descriptions that explain what to look for
  3. Use a system prompt that instructs the model to infer values from context
  4. Mark fields as nullable if they are truly optional

Timeout Issues

Request Timeout

Error:
Solution: The API call took longer than the configured timeout. This is common with large inputs, complex response models, or heavily loaded provider APIs. Increase the timeout in configuration:
Or override per-request using options:

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:
In production, consider running streaming extractions in a queue worker where time limits are typically more generous.

Testing Issues

Fake Not Working

Problem: Real API calls are made despite using fake(). 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.
Also verify that your test environment is not overriding this setting via an environment variable.

Performance Issues

Slow Responses

Solutions:
  1. Use a faster modelgpt-4o-mini is significantly faster than gpt-4o for simple extractions
  2. Use a fast-inference provider — Groq offers very low latency for supported models
  3. Enable response caching — avoid redundant calls for identical inputs
  4. Reduce input size — truncate long inputs to the minimum necessary context

High Token Usage

Solutions:
  1. Use concise system prompts — every token in the prompt counts toward your bill
  2. Truncate long inputs to the essential content
  3. Use smaller response models with fewer properties
  4. Choose a model with a lower per-token cost

Memory Issues

Out of Memory

Error:
Solution: This can happen when processing many documents in a single request. Strategies:
  1. Process documents in chunks and allow garbage collection between batches
  2. Use streaming for large responses
  3. Dispatch extraction jobs to a queue worker with higher memory limits

Common Error Messages


Getting Help

If you are still stuck after trying the solutions above:
  1. Check the logs for detailed error information:
  2. Enable debug logging for maximum visibility into what is happening:
  3. Test the API directly to isolate whether the issue is in your configuration or your code:
  4. Search existing issues on GitHub: https://github.com/cognesy/instructor-php/issues
  5. 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