Instructor offers several ways to debug it’s internal state and execution flow.

Events

Instructor emits events at various points in its lifecycle, which you can listen to and react to. You can use these events to debug execution flow and to inspect data at various stages of processing.

For more details see the Events section.

HTTP Debugging

The Instructor class has a withDebug() method that can be used to debug the request and response.

$result = (new Instructor)->withDebug()->respond(
    messages: "Jason is 25 years old",
    responseModel: User:class,
);

It displays detailed information about the request being sent to LLM API and response received from it, including:

  • request headers, URI, method and body,
  • response status, headers, and body.

This is useful for debugging the request and response when you are not getting the expected results.

Debugging SaloonPHP requests

You can also directly access Saloon connector instance via connector() method on the client instance, and call Saloon debugging methods on it - see SaloonPHP debugging documentation for more details: https://docs.saloon.dev/the-basics/debugging

Additionally, connector() method on the client instance allows you to access other capabilities of Saloon connector, such as setting or modifying middleware. See SaloonPHP documentation for more details: https://docs.saloon.dev/digging-deeper/middleware