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
feat(dspy): custom type resolution in Signatures (#8232)
* initial version - custom types working
* refactor custom type class to be nicer
* [will fail CI] Move tests to separate file + add module level test to fail
* Dynamically walk call stack to find more types
* ruff + extra
* simplify docs
Copy file name to clipboardExpand all lines: docs/docs/learn/programming/signatures.md
+36Lines changed: 36 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,13 @@ Your signatures can also have multiple input/output fields with types:
32
32
33
33
**Tip:** For fields, any valid variable names work! Field names should be semantically meaningful, but start simple and don't prematurely optimize keywords! Leave that kind of hacking to the DSPy compiler. For example, for summarization, it's probably fine to say `"document -> summary"`, `"text -> gist"`, or `"long_context -> tldr"`.
34
34
35
+
You can also add instructions to your inline signature, which can use variables at runtime. Use the `instructions` keyword argument to add instructions to your signature.
36
+
37
+
```python
38
+
toxicity = dspy.Predict(
39
+
'comment -> toxic: bool',
40
+
instructions="Mark as 'toxic' if the comment includes insults, harassment, or sarcastic derogatory remarks.")
41
+
```
35
42
36
43
### Example A: Sentiment Classification
37
44
@@ -157,6 +164,35 @@ Prediction(
157
164
)
158
165
```
159
166
167
+
## Type Resolution in Signatures
168
+
169
+
DSPy signatures support various annotation types:
170
+
171
+
1.**Basic types** like `str`, `int`, `bool`
172
+
2.**Typing module types** like `List[str]`, `Dict[str, int]`, `Optional[float]`. `Union[str, int]`
173
+
3.**Custom types** defined in your code
174
+
4.**Dot notation** for nested types with proper configuration
175
+
5.**Special data types** like `dspy.Image, dspy.History`
0 commit comments