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
* Add guards against loading pkl files
* remove extra comment
* add tests and modify old tests
* add import and fix tests
* Update test to allow loading of pickled models with a safety flag
* Change from dangersouly_allow_pickle to allow_pickle, remove env var, and suggest saving with module.save(x.json)
* fix extra whitespace
* fix test warning
Copy file name to clipboardExpand all lines: docs/docs/tutorials/games/index.ipynb
+8-1Lines changed: 8 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -746,14 +746,21 @@
746
746
"If you want to load and use the agent program, you can do that as follows."
747
747
]
748
748
},
749
+
{
750
+
"cell_type": "markdown",
751
+
"metadata": {},
752
+
"source": [
753
+
"> **⚠️ Security Warning:** Loading `.pkl` files can execute arbitrary code and may be dangerous. Only save and load pickle files from trusted sources in secure environments. Consider using JSON format when possible for safer serialization."
To save the state of your program to a pickle file:
40
40
41
+
!!! danger "Security Warning: Pickle Files Can Execute Arbitrary Code"
42
+
Loading `.pkl` files can execute arbitrary code and may be dangerous. Only load pickle files from trusted sources in secure environments. **Prefer using `.json` files whenever possible**. If you must use pickle files, ensure you trust the source and use the `allow_pickle=True` parameter when loading.
!!! warning "Security Notice: Whole Program Saving Uses Pickle"
80
+
Whole program saving uses `cloudpickle` for serialization, which has the same security risks as pickle files. Only load programs from trusted sources in secure environments.
81
+
73
82
Starting from `dspy>=2.6.0`, DSPy supports saving the whole program, including the architecture and the state. This feature
74
83
is powered by `cloudpickle`, which is a library for serializing and deserializing Python objects.
This method is used to load a saved DSPy model with `save_program=True`, i.e., the model is saved with cloudpickle.
31
31
32
32
Args:
33
33
path (str): Path to the saved model.
34
+
allow_pickle (bool): Whether to allow loading the model with pickle. This is dangerous and should only be used if you are sure you trust the source of the model.
34
35
35
36
Returns:
36
37
The loaded model, a `dspy.Module` instance.
37
38
"""
39
+
ifnotallow_pickle:
40
+
raiseValueError("Loading with pickle is not allowed. Please set `allow_pickle=True` if you are sure you trust the source of the model.")
41
+
38
42
path=Path(path)
39
43
ifnotpath.exists():
40
44
raiseFileNotFoundError(f"The path '{path}' does not exist.")
0 commit comments