Skip to main content

ask_json

Function ask_json 

Source
pub async fn ask_json(
    model: &(dyn BaseChatModel + Send + Sync),
    prompt: &str,
    system_prompt: &str,
) -> Result<Option<Value>, RunnableError>
Expand description

Ask the LLM a single prompt and get back a parsed JSON value.

This combines three steps that are repeated in every “structured output” node:

  1. Call stream_llm with a raw prompt (no state extraction)
  2. Extract the response text
  3. Parse JSON (stripping markdown fences if present)

Returns None when the response is not valid JSON.

§Example

let plan = ask_json(model, "Create a plan in JSON format", "").await;