Skip to content

Commit 5eaf1df

Browse files
committed
Update Blog “using-structured-outputs-in-vllm”
1 parent 600221a commit 5eaf1df

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

content/blog/using-structured-outputs-in-vllm.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tags:
1212
- LLM
1313
---
1414
<style> li { font-size: 27px; line-height: 33px; max-width: none; } </style>
15-
Generating predictable and reliable outputs from large language models (LLMs) can be challenging, especially when those outputs need to integrate seamlessly with downstream systems. Structured outputs solve this problem by enforcing specific formats, such as JSON, regex patterns, or even grammars. vLLM, an open source inference and serving engine for LLMs, supports structured outputs since some time ago, but there were no documentation on how to use it supported this since some time ago, but there were no documentation on how to use it, and that´s why I decided to do a contribution and write the [Structured Outputs documentation page](https://docs.vllm.ai/en/latest/usage/structured_outputs.html).
15+
Generating predictable and reliable outputs from large language models (LLMs) can be challenging, especially when those outputs need to integrate seamlessly with downstream systems. Structured outputs solve this problem by enforcing specific formats, such as JSON, regex patterns, or even formal grammars. vLLM, an open source inference and serving engine for LLMs, has supported structured outputs for a while. However, there is little documentation on how to use it. This is why I decided to contribute and write the [Structured Outputs documentation page](https://docs.vllm.ai/en/latest/usage/structured_outputs.html).
1616

1717
In this blog post, I'll explain how structured outputs work in vLLM and walk you through how to use them effectively.
1818

@@ -24,9 +24,9 @@ LLMs are incredibly powerful, but their outputs can be inconsistent when a speci
2424
2. **Compatibility:** Seamless integration with APIs, databases, or other systems.
2525
3. **Efficiency:** No need for extensive post-processing to validate or fix outputs.
2626

27-
Imagine we have an external system which receives a JSON with the all the details to trigger an alert, and we want our LLM-based system to be able to use it. Of course we can try to explain the LLM what should be the output format and that it must be a valid JSON, but LLMs are not deterministic and thus we may end up with an invalid JSON. Probably, if you have tried to do something like this before, you would have found yourself in this situation.
27+
Imagine there is an external system which receives a JSON object with the all the details to trigger an alert, and you want your LLM-based system to be able to use it. Of course you could try to explain the LLM what should be the output format and that it must be a valid JSON object, but LLMs are not deterministic and thus we may end up with an invalid JSON. Probably, if you have tried to do something like this before, you would have found yourself in this situation.
2828

29-
How these tools work? The idea is that we´ll be able to filter the list of possible next tokens to force that we are always generating a token that is valid for the desired output format.
29+
How do these tools work? The idea behind them is to filter a list of possible next tokens to force a valid token to be generated that produces the desired output format, for example, a valid JSON object.
3030

3131
![Structured outputs in vLLM](/img/structured_outputs_thumbnail.png "Structured outputs in vLLM")
3232

@@ -53,7 +53,7 @@ Here’s how each works, along with example outputs:
5353

5454
### **1. Guided choice**
5555

56-
Simplest form of structured output, ensuring the response is one of a set of predefined options.
56+
Guided choice is the simplest form of structured output. It ensures the response is one from of a set of predefined options.
5757

5858
```python
5959
from openai import OpenAI
@@ -78,7 +78,7 @@ positive
7878

7979
### **2. Guided Regex**
8080

81-
Constrains output to match a regex pattern, useful for formats like email addresses.
81+
A guided regex constrains the output to match a regex pattern, which is useful for formats like email addresses.
8282

8383
```python
8484
completion = client.chat.completions.create(
@@ -102,7 +102,7 @@ [email protected]
102102

103103
### **3. Guided JSON**
104104

105-
Enforces a valid JSON format based on a schema, simplifying integration with other systems.
105+
Guided JSON enforces a valid JSON format based on a schema, simplifying integration with other systems.
106106

107107
```python
108108
from pydantic import BaseModel
@@ -143,7 +143,7 @@ print(completion.choices[0].message.content)
143143

144144
### **4. Guided grammar**
145145

146-
Uses an Extended BackusNaur Form (EBNF) grammar to define complex output structures, such as SQL queries.
146+
Guided grammar uses an Extended Backus-Naur Form (EBNF) grammar syntax to define complex output structures, such as SQL queries.
147147

148148
```python
149149
completion = client.chat.completions.create(

0 commit comments

Comments
 (0)