Be specific in your questions to get accurate results
Use structured schemas for complex data extraction
Validate extracted data before using it
Copy
Ask AI
from askui import ResponseSchemaBaseclass ProductInfo(ResponseSchemaBase): name: str price: float in_stock: bool# Specific query with schemaproduct = agent.get( "What is the product name, price, and stock status?", response_schema=ProductInfo)
When extracting data from UI elements, consider these optimization strategies:
Batch Extraction
Instead of multiple calls:
Copy
Ask AI
# Inefficientname = agent.get("What is the username?", response_schema=str)email = agent.get("What is the email?", response_schema=str)role = agent.get("What is the role?", response_schema=str)# Efficient - single extractionclass UserInfo(ResponseSchemaBase): name: str email: str role: struser = agent.get("Extract user information", response_schema=UserInfo)
Caching Results
Copy
Ask AI
class DataCache: def __init__(self): self._cache = {} def get_or_extract(self, agent, key, question, schema): if key not in self._cache: self._cache[key] = agent.get(question, response_schema=schema) return self._cache[key]cache = DataCache()# Reuse expensive extractionstable_data = cache.get_or_extract( agent, 'main_table', "Extract the main data table", List[dict])