| name | prompt-args |
| description | JOB-254 — PromptArgs pitfalls, required key validation, and typed input patterns. |
PromptArgs is HashMap. Missing keys cause runtime panics. Always match
prompt_args! keys exactly to template_fstring! variable names.
## Type Definition
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! Macro
use langchainx::prompt_args;
let args = prompt_args! {
"input" => "Hello world",
"context" => "Some context",
"count" => 42,
};
Values are converted via serde_json::json!. Any Serialize type works.
## Chain Input Key Contracts
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
let prompt = message_formatter![fmt_template!(
HumanMessagePromptTemplate::new(template_fstring!("{question}", "question"))
)];
let args = prompt_args! { "input" => "What is Rust?" };
let args = prompt_args! { "question" => "What is Rust?" };