Structured output allows you to define the exact shape of the agent’s response using JSON Schema. This ensures you receive data in a predictable, parseable format.
The answerFormat field accepts a JSON Schema that defines the structure of the agent’s answer:
from subconscious import Subconsciousclient = Subconscious(api_key="your-api-key")run = client.run( engine="tim", input={ "instructions": "Analyze the sentiment of this review: 'Great product, fast shipping!'", "tools": [], "answerFormat": { "type": "object", "title": "SentimentAnalysis", "properties": { "sentiment": { "type": "string", "enum": ["positive", "negative", "neutral"], "description": "The overall sentiment" }, "confidence": { "type": "number", "description": "Confidence score from 0 to 1" }, "keywords": { "type": "array", "items": {"type": "string"}, "description": "Key phrases that influenced the sentiment" } }, "required": ["sentiment", "confidence", "keywords"] } }, options={"await_completion": True},)# `answer` is the raw JSON string; `parsed_answer` is the decoded dictresult = run.result.parsed_answerprint(result["sentiment"]) # "positive"print(result["confidence"]) # 0.95print(result["keywords"]) # ["Great product", "fast shipping"]
run.result.answer is always a string. When you supply an answerFormat,
the agent’s structured output arrives as a JSON-encoded string — the SDK
decodes it for you and attaches the native value as
run.result.parsed_answer (Python) or run.result.parsedAnswer
(TypeScript). Use answer when you need the raw payload, and
parsed_answer / parsedAnswer when you want to read fields directly.