Skip to main content
LangSmith provides a convenient integration with Instructor, a popular open-source library for generating structured output with LLMs.
In an agent-based workspace, create an agent once before sending traces. Use agent addressing to select its identifier and environment. If an integration requires project_name, use the selected environment’s tracer_session_name as a compatibility value.
In order to use, you first need to set your LangSmith API key.
Next, you will need to install the LangSmith SDK:
Wrap your OpenAI client with langsmith.wrappers.wrap_openai
After this, you can patch the wrapped OpenAI client using instructor:
Now, you can use instructor as you normally would, but now everything is logged to LangSmith!
Oftentimes, you use instructor inside of other functions. You can get nested traces by using this wrapped client and decorating those functions with @traceable. Please see Custom instrumentation for more information on how to annotate your code for tracing with the @traceable decorator.