Home Explore Blog CI



ragit

2nd chunk of `docs/pdl_format.md`
0364f50cf53b7bfa4620faddbd5e6d63496e4aff3d35578900000001000008ec
### Non-json schema

Basically, pdl engine first extracts json-looking string from LLM output, then parses it. For example, if the schema is a json object, the engine tries to match a curly brace using regular expression. If it fails to parse json, that's an error.

There are 4 cases where it doesn't parse json.

1. If the schema is `str`, it just treats the entire output as the string. It doesn't look for quotation marks, and it doesn't run the parser. You can also add constraints to `str`. For example, if the schema is `str { min: 100 }`, it makes sure that the length of the entire output is at least 100 characters.
2. If the schema is `yesno`, it makes sure that the LLM's output is either `yes` or `no`. You cannot mix it with other json schema because `yes` and `no` are not valid json values. If yes/no is all you need, `yesno` is better than `bool` because LLMs are usually better at English than json. This type is later converted to a boolean value, `serde_json::Value::Bool` in Rust.
3. If the schema is `code`, it looks for a [markdown code block](https://github.github.com/gfm/#fenced-code-blocks). This type is later converted to a string value, `serde_json::Value::String` in Rust. The string is the content of the fenced code block, without the fences.
4. If the schema is `tasklist`, it looks for a [markdown task list](https://github.github.com/gfm/#task-list-items-extension-). It extracts the task list from LLM output and converts the list to a string value, `serde_json::Value::String` in Rust.

## Examples

### An image

```
<|user|>

<|media(assets/sample_image.png)|>

What do you see in the image?
```

When you run this pdl file with a multi-modal model, the model will tell you what it sees in the image.

### A simple schema 1: boolean

```
<|schema|>

bool

<|user|>

Is Rust a strictly typed programming language? Just say "true" or "false".
```

If the model's response has no "true" or "false", it will automatically prompt the model to "just say true or false".

### A simple schema 2: yes/no

```
<|schema|>

yesno

<|user|>

Is Rust a strictly typed programming language? Just say yes or no.
```

It's like a boolean schema, but it will make the model say yes or no. It's better sometimes since most models are better at English than json.

Title: Non-JSON Schema and Examples in PDL
Summary
The PDL engine supports non-JSON schema types, including 'str', 'yesno', 'code', and 'tasklist', which allow for more flexible output parsing and validation, and provides examples of using these schema types and image embedding in PDL files to interact with multi-modal models.