Skip to main content

construct_structured_response

Function construct_structured_response 

Source
pub fn construct_structured_response<'py>(
    py: Python<'py>,
    text: String,
    output_model: Option<&Bound<'py, PyAny>>,
) -> Result<Bound<'py, PyAny>, UtilError>
Expand description

Helper function to extract result from LLM response text If an output model is provided, it will attempt to convert the text to the structured output using the provided model. If no model is provided, it will attempt to convert the response to an appropriate Python type directly.

§Arguments

  • py - A Python interpreter instance
  • text - The text to be converted (typically from an LLM response)
  • output_model - An optional bound python object representing the output model

§Returns

  • Result<Bound<'py, PyAny>, UtilError> - A result containing the structured output or an error