StructuredOutputHandler
- Generate prompts that guide agents to produce structured output
- Extract structured data from agent responses using regex patterns
- Provide fallback mechanisms when extraction fails
- Support the existing structured output schemas used in workforce.py
generate_structured_prompt
- base_prompt (str): The base prompt content.
- schema (Type[BaseModel]): The Pydantic model schema for the expected output.
- examples (Optional[List[Dict[str, Any]]]): Optional examples of valid output.
- additional_instructions (Optional[str]): Additional instructions for output formatting.
extract_json
- text (str): The text containing JSON data.
- schema (Optional[Type[BaseModel]]): Optional schema for targeted extraction.
_extract_with_schema_patterns
- text (str): The text to extract from.
- schema (Type[BaseModel]): The schema to use for extraction.
parse_structured_response
- response_text (str): The agent’s response text.
- schema (Type[BaseModel]): The expected schema.
- fallback_values (Optional[Dict[str, Any]]): Fallback values to use if parsing fails.
_fix_common_issues
- data (Dict[str, Any]): The extracted data.
- schema (Type[BaseModel]): The target schema.
_create_default_instance
- schema (Type[BaseModel]): The schema to instantiate.
validate_response
- response: The response to validate.
- schema (Type[BaseModel]): The expected schema.
create_fallback_response
- schema (Type[BaseModel]): The schema to create a response for.
- error_message (str): The error message to include.
- context (Optional[Dict[str, Any]]): Additional context for the fallback.