一键导入
prompt-args
JOB-254 — PromptArgs pitfalls, required key validation, and typed input patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
JOB-254 — PromptArgs pitfalls, required key validation, and typed input patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait.
JOB-251 — Why Arc<dyn LLM> over LLMClone, migration pattern, and correct LLM ownership model.
All Chain types — LLMChain, ConversationalChain, SequentialChain, StuffDocuments, ConversationalRetrievalQA, SqlDatabaseChain.
Trait conformance tests, property-based tests (proptest), fuzz targets, and boundary contracts for langchainx traits.
Core langchainx patterns — LLMChain, builder pattern, Chain trait, prompt macros, and basic invocation.
Constructing LLM backends (OpenAI, Claude, DeepSeek, Qwen, Ollama) and configuring CallOptions.
| name | prompt-args |
| description | JOB-254 — PromptArgs pitfalls, required key validation, and typed input patterns. |
// src/prompt/mod.rs
pub type PromptArgs = HashMap<String, serde_json::Value>;
It is an alias — not a newtype. There is no compile-time enforcement of required keys.
## prompt_args! Macrouse langchainx::prompt_args;
let args = prompt_args! {
"input" => "Hello world",
"context" => "Some context",
"count" => 42,
};
// Expands to HashMap::from([("input".to_string(), json!("Hello world")), ...])
Values are converted via serde_json::json!. Any Serialize type works.
Each chain documents its required keys. These are checked only at runtime.
| Chain | Required keys |
|---|---|
LLMChain | whatever variables are in the prompt template |
ConversationalChain | "input" |
ConversationalRetrieverChain | "input" |
AgentExecutor | "input" (hardcoded) |
Use chain.get_input_keys() to inspect at runtime:
let keys = chain.get_input_keys();
assert!(keys.contains(&"input".to_string()));
## Validating Keys Before Calling (current best practice)
Until JOB-254 is resolved, validate manually:
fn validate_args(chain: &dyn Chain, args: &PromptArgs) -> Result<(), ChainError> {
for key in chain.get_input_keys() {
if !args.contains_key(&key) {
return Err(ChainError::MissingObject(
format!("missing required input key: '{key}'")
));
}
}
Ok(())
}
## Common Mistake: Key Mismatch
// Template uses "question" but args use "input"
let prompt = message_formatter![fmt_template!(
HumanMessagePromptTemplate::new(template_fstring!("{question}", "question"))
)];
// WRONG
let args = prompt_args! { "input" => "What is Rust?" };
// chain.invoke(args) → runtime error: missing variable "question"
// CORRECT
let args = prompt_args! { "question" => "What is Rust?" };