An llm plugin to add structured JSON output support to LLMs
Project description
LLM Structured Outputs
A plugin for the llm CLI tool that enables structured output generation from language models according to a specified schema. For usability, users can define their desired schema in YAML.
Features
- 🔧 Generate structured outputs according to a simple YAML definition
- 🔄 Support for nested objects and references
- 🤖 Uses OpenAI's native structured output API mode
- 🛡️ Built-in validation using Pydantic
Installation
Assuming you have llm installed already, simply run:
llm install -U llm-structure
Usage
Schema Definition
Create a YAML file defining your schema. Note the use of $ref which allows for lists of objects in this case. This is the same as defining List[People].
# people.yaml
People:
type: array
items:
$ref: "#/Person"
Person:
name: str
age: int
Then run the plugin:
llm structure "Chase, 53, and 49 year old Mia went to the market." --schema people.yaml -m gpt-4o
Alternatively, you can use STDIN by specifying - as the prompt:
echo "Chase, 53, and 49 year old Mia went to the market." | llm structure - --schema people.yaml -m gpt-4o
This prints output directly to the console in JSON format:
{
"items": [
{
"name": "Chase",
"age": 53
},
{
"name": "Mia",
"age": 49
}
]
}
Supported Models
Currently supports OpenAI models:
- o1-2024-12-17 and later
- gpt-4o-mini-2024-07-18 and later
- gpt-4o-2024-08-06 and later
Integration with Gemini (native) and instructor for the balance of models is coming soon.
Requirements
- Python 3.8+
- llm
- PyYAML
- Pydantic
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_structure-0.1.0.tar.gz.
File metadata
- Download URL: llm_structure-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd402f6daf3264a69ce94fdca63bc696d4b3aa7b42a375b9e3950267a1543870
|
|
| MD5 |
92685fca5b81b50b9e9212392ad9d766
|
|
| BLAKE2b-256 |
d44c8685494ea6bfd9875b3d9d21bc7cae9d47d444d3857592a84513e357f36c
|
File details
Details for the file llm_structure-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_structure-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e72fdf3de931c85580637303766b008ca9cce0f93a2f5d4545031f0e49dff3
|
|
| MD5 |
2e37d318af0224f714c2745c4998740f
|
|
| BLAKE2b-256 |
9c386a1ec2df67bc895bc8db02735702bfecd983d1544b348ea0b0e351b2c489
|