EnhancementResult
EnhancementResult is the primary output object returned by ad-enhancement
calls. It carries both success and fallback outcomes in a single, consistent
shape.
Class purpose
This class exists to make application handling deterministic:
- your pipeline always receives a prompt to continue execution;
- success and failure state are explicit via
successanderror; - conversation metadata is always preserved on the result; and
- backend response payload is available when present.
Class shape
- Python
from adstractai import Adstract
from adstractai.models import AdRequestConfiguration
client = Adstract(api_key="your-api-key")
result = client.request_ad_or_default(
prompt="Explain SOC 2 for startups.",
config=AdRequestConfiguration(
session_id="sess-100",
user_agent="Mozilla/5.0 (X11; Linux x86_64)",
x_forwarded_for="203.0.113.10",
),
)
Field reference
-
prompt- Type:
str - Meaning: Final prompt your application should use in the LLM call.
- Behavior:
- Enhanced prompt when ad enhancement succeeds.
- Original prompt when fallback is used.
- Type:
-
conversation- Type:
Conversation - Meaning: Resolved conversation context for tracking and reporting continuity.
- Type:
-
ad_response- Type:
AdResponse | None - Meaning: Parsed backend response when available.
- Behavior:
- Can be
Nonein error/fallback scenarios.
- Can be
- Type:
-
success- Type:
bool - Meaning: Outcome flag for enhancement operation.
- Behavior:
Truewhen enhancement succeeded.Falsewhen fallback path was used.
- Type:
-
error- Type:
Exception | None - Meaning: Captured failure context.
- Behavior:
- Populated when enhancement fails.
Noneon successful enhancement.
- Type:
Handling pattern
- Python
if result.success:
prompt_for_model = result.prompt
else:
print(result.error)
prompt_for_model = result.prompt
Next steps
- Continue to Initialize Your Integration to initialize the runtime before enhancement calls.
- Continue to Synchronous Analytics and Reporting for sync reporting flow.
- Continue to Asynchronous Analytics and Reporting for async reporting flow.
- Continue to Exception for runtime error type handling.