Coerce a step's free-text output into a JSON object validated against `schema`, reusing the structured-output machinery (Tool mode — the most portable across providers, with built-in repair). This is one extra LLM call beyond the step's own run.
(
&self,
output: &str,
schema: serde_json::Value,
)
| 620 | /// portable across providers, with built-in repair). This is one extra LLM |
| 621 | /// call beyond the step's own run. |
| 622 | async fn coerce_to_schema( |
| 623 | &self, |
| 624 | output: &str, |
| 625 | schema: serde_json::Value, |
| 626 | ) -> Result<serde_json::Value> { |
| 627 | let req = StructuredRequest { |
| 628 | prompt: format!( |
| 629 | "Convert the following task result into a single JSON object that conforms to \ |
| 630 | the required schema. Use only information present in the result.\n\n\ |
| 631 | --- TASK RESULT ---\n{output}" |
| 632 | ), |
| 633 | system: Some( |
| 634 | "You output exactly one JSON object matching the provided schema.".to_string(), |
| 635 | ), |
| 636 | schema, |
| 637 | schema_name: "step_output".to_string(), |
| 638 | schema_description: None, |
| 639 | // Tool mode works on every provider that supports tool use and |
| 640 | // does not depend on response_format wiring. |
| 641 | mode: StructuredMode::Tool, |
| 642 | max_repair_attempts: 2, |
| 643 | }; |
| 644 | let result = generate_blocking(&*self.llm_client, &req).await?; |
| 645 | Ok(result.object) |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | /// Get the JSON schema for TaskParams |
no test coverage detected