Output Modes
MdJSON Mode
Learn how to use Markdown JSON mode in Polyglot for structured LLM responses.
Markdown JSON mode is a special mode that requests the model to format its response as JSON within a Markdown code block. This is particularly useful for models or providers that don’t have native JSON output support.
Using Markdown JSON Mode
How MdJson Mode Works
- Polyglot instructs the model to respond with a JSON object wrapped in a Markdown code block
- The model formats its response accordingly (
json {...}
) - Polyglot extracts the JSON content from the Markdown code block
- The JSON is parsed and returned to your application
Providing Guidance for MdJson
While MdJson is more flexible across providers, you still need to provide clear instructions:
EOT;
inference->create( messages: $prompt, mode: Mode::MdJson )->toJson();
// Process as normal JSON