prompt
parameter in the
create()
method.
It will override the default Instructor prompts, allowing you to fully
customize how LLM is instructed to process the input.
OutputMode::Tools
is usually most reliable way to get structured outputs following
provided response schema.
OutputMode::Tools
can make use of $toolName
and $toolDescription
parameters
to provide additional semantic context to the LLM, describing the tool to be used
for processing the input. OutputMode::Json
and OutputMode::MdJson
ignore these parameters,
as tools are not used in these modes.
OutputMode::Json
and OutputMode::MdJson
.
OutputMode::Json
uses JSON mode offered by some models and API providers to get LLM
respond in JSON format rather than plain text.
JSON
string in the prompt.
response_format
parameter, but this may not be sufficient for some models or providers -
some of them require specifying JSON response format as part of the
prompt, rather than just as response_format
parameter in the request
(e.g. OpenAI).
For this reason, when using Instructor’s OutputMode::Json
and OutputMode::MdJson
you should include the expected JSON Schema in the prompt. Otherwise, the
response is unlikely to match your target model, making it impossible for
Instructor to deserialize it correctly.
<|variable|>
placeholders in the template string, which will be replaced
with the actual values during the execution.
Currently, the following placeholders are supported:
<|json_schema|>
- replaced with the JSON Schema for current response modelOutputMode::MdJson
is the most basic (and least reliable) way to get structured
outputs from LLM. Still, you may want to use it with the models which do not
support tool calling or JSON output.
OutputMode::MdJson
relies on the prompting to get LLM response in JSON formatted data.
Many models prompted in this mode will respond with a mixture of plain text and JSON
data. Instructor will try to find JSON data fragment in the response and ignore
the rest of the text.
This approach is most prone to deserialization and validation errors and needs
providing JSON Schema in the prompt to increase the probability that the response
is correctly structured and contains the expected data.