You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-21Lines changed: 38 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,3 @@
1
-
:::thinking
2
-
Let me create a comprehensive README.md file for the PydanticPrompt project, incorporating the development instructions, examples, and other important information.
3
-
4
-
The updated README should include:
5
-
1. Introduction and description
6
-
2. Installation instructions
7
-
3. Usage examples with various scenarios
8
-
4. Development setup
9
-
5. License information
10
-
11
-
I'll use the markdown content we've developed so far and organize it into a cohesive document.
12
-
:::
13
1
# PydanticPrompt
14
2
15
3
A simple library to document [Pydantic](https://docs.pydantic.dev/) models for structured LLM outputs using standard Python docstrings.
@@ -25,7 +13,8 @@ pip install pydantic-prompt
25
13
- Document Pydantic model fields using standard Python docstrings
26
14
- Format field documentation for LLM prompts with a single method call
27
15
- Automatic type inference and display
28
-
- Optional validation rule display
16
+
- Optional validation rule documentation
17
+
- Warnings for undocumented fields
29
18
- Seamlessly embeds documentation in your prompts
30
19
31
20
## Usage
@@ -35,9 +24,9 @@ pip install pydantic-prompt
35
24
```python
36
25
from pydantic import BaseModel, Field
37
26
from typing import Optional
38
-
from pydantic_prompt importllm_documented
27
+
from pydantic_prompt importprompt_schema
39
28
40
-
@llm_documented
29
+
@prompt_schema
41
30
classPerson(BaseModel):
42
31
name: str
43
32
"""The person's full name"""
@@ -73,10 +62,10 @@ Person:
73
62
74
63
```python
75
64
from pydantic import BaseModel
76
-
from pydantic_prompt importllm_documented
65
+
from pydantic_prompt importprompt_schema
77
66
from typing import List
78
67
79
-
@llm_documented
68
+
@prompt_schema
80
69
classAddress(BaseModel):
81
70
street: str
82
71
"""Street name and number"""
@@ -87,7 +76,7 @@ class Address(BaseModel):
87
76
postal_code: str
88
77
"""Postal or ZIP code"""
89
78
90
-
@llm_documented
79
+
@prompt_schema
91
80
classContact(BaseModel):
92
81
name: str
93
82
"""Full name of the contact"""
@@ -116,14 +105,42 @@ Person:
116
105
- email (str, optional): Contact email address if available
117
106
```
118
107
108
+
### Warnings for Undocumented Fields
109
+
110
+
By default, PydanticPrompt warns you when fields don't have docstrings:
111
+
112
+
```python
113
+
@prompt_schema
114
+
classPartiallyDocumented(BaseModel):
115
+
name: str
116
+
"""This field has a docstring"""
117
+
118
+
age: int
119
+
# Missing docstring will generate a warning
120
+
```
121
+
122
+
Output:
123
+
```
124
+
UserWarning: Field 'age' in PartiallyDocumented has no docstring. Add a docstring for better LLM prompts.
125
+
```
126
+
127
+
To disable these warnings:
128
+
129
+
```python
130
+
@prompt_schema(warn_undocumented=False)
131
+
classSilentModel(BaseModel):
132
+
name: str
133
+
# No warning for missing docstring
134
+
```
135
+
119
136
## Real-World Example
120
137
121
138
```python
122
139
from pydantic import BaseModel, Field
123
-
from pydantic_prompt importllm_documented
140
+
from pydantic_prompt importprompt_schema
124
141
from typing import List
125
142
126
-
@llm_documented
143
+
@prompt_schema
127
144
classProductReview(BaseModel):
128
145
product_name: str
129
146
"""The exact name of the product being reviewed"""
0 commit comments