DSPy 程序化 Prompt 优化
DSPy:把 LLM 程序写成可组合 Module + 声明式 Signature 的 Python 框架。通过 14 个 teleprompter(optimizer)从 train + dev 集自动编译 prompt 与 few-shot demo。
晶体简介
Constraints
Evidence Quality
High confidence — strong evidence base
8 条不可违反的约束
WHENWhen configuring DSPy in any production / multi-tenant / shared-CI environment that points DSPY_CACHEDIR (or default ~/.dspy_cache) at a writable shared location
ACTIONcall dspy.configure_cache(restrict_pickle=True) (and register safe_types as needed) so the global Cache instance routes diskcache reads through the restricted unpickler in dspy/clients/disk_serialization.py
CONSEQUENCEDefault Cache(restrict_pickle=False) at clients/__init__.py:88 routes Cache.get() through diskcache pickle.load WITHOUT a restricted unpickler; a poisoned ~/.dspy_cache shard (CI shared volume, dependency confusion, multi-tenant host) triggers arbitrary code execution at fetch time with NO user opt-in
WHENWhen writing tutorials / SKILL configs / setup scripts that load saved DSPy programs or memory caches (BaseModule.load / dspy.load / Settings.load / Cache.load_memory_cache)
ACTIONrecommend or default-set allow_pickle=True without documenting source provenance verification — every public .load(...) defaults allow_pickle=False; tutorials that flip the default normalize disabling the framework-side gate
CONSEQUENCEBaseModule.load:268-271, dspy.load saving.py:39-40, Settings.load:298-315, Cache.load_memory_cache:201-206 each gate cloudpickle.load behind allow_pickle=False default. A tutorial-recommended allow_pickle=True silently turns those gates into theater, enabling RCE via attacker-supplied .pkl bundles
WHENWhen launching MIPROv2 (or any prompt-optimization run) on a paid LM provider
ACTIONcompute the cost ceiling explicitly from num_candidates, num_trials, num_predictors, and valset size BEFORE calling teleprompter.compile() — MIPROv2._estimate_lm_calls only PRINTS the estimate; there is no max_total_calls knob
CONSEQUENCEMisconfigured auto='heavy' on 18 candidates × 10 predictors × 1000 valset can burn hundreds of dollars silently in 20 minutes — _estimate_lm_calls at mipro_optimizer_v2.py:355-401 only prints ANSI-colored estimates and returns strings; there is no raise / no abort if estimated > budget
常见问题
讨论 (0)
暂无讨论,成为第一个发言的人吧!
更新历史
v0.1.0: 首次发布到 Doramagic.ai。基于 stanfordnlp/dspy 的 LLM 程序优化框架,中英双语 + 44 条 anti-pattern 约束(8 条 fatal)+ 3 条 FAQ。
v0.1.0: 首次发布到 Doramagic.ai。基于 stanfordnlp/dspy 的 LLM 程序优化框架,中英双语 + 44 条 anti-pattern 约束(8 条 fatal)+ 3 条 FAQ。