Asynchronous Analytics and Reporting
analyse_and_report_async is the asynchronous reporting method in Adstract.
It analyzes the final LLM response after enhancement and sends acknowledgment
payloads to Adstract using async transport.
Why this method is critical
This method closes the full ad workflow cycle in async pipelines.
- It confirms that the enhancement flow reached final output handling.
- It submits the required acknowledgment data for reporting.
- It is required for publisher-side monetization flow, because the reporting confirmation is part of how ad placement opportunity is accounted for.
Method signature
- Python
await client.analyse_and_report_async(
enhancement_result=result,
llm_response=llm_response,
)
Inputs
-
enhancement_result- Type:
EnhancementResult - Meaning: Result returned from the enhancement method.
- Role: Source object used for analytics/reporting context.
- Type:
-
llm_response- Type:
str - Meaning: Final text returned by your LLM.
- Role: Content analyzed for ad usage and reporting metrics.
- Type:
For result object details, see EnhancementResult.
Output
This method returns None.
Behavior model
The method flow is:
- Check whether enhancement succeeded.
- If enhancement did not succeed, reporting is skipped.
- If enhancement succeeded, build analytics and acknowledgment payload.
- Send the reporting payload to Adstract asynchronously.
- If analysis/reporting fails, attempt to send an error acknowledgment payload.
- Re-raise the original analysis/reporting exception after error reporting attempt.
Exception behavior
Unlike fallback enhancement methods, analyse_and_report_async may raise.
- If reporting/analysis fails, the method tries to submit an error reporting payload first.
- After that attempt, it re-raises the original exception so callers can handle failure explicitly.
For full exception reference, see Exception.
Privacy and data-protection note
The raw final LLM response text is not sent to the backend.
- Reporting sends derived analytics and tracking metadata.
- Sensitive content handling is minimized by design.
- The flow is designed with privacy, safety, and data-protection constraints in mind.
Minimal async integration pattern
- Python
import asyncio
from adstractai import Adstract
from adstractai.models import AdRequestConfiguration
async def main() -> None:
client = Adstract(api_key="your-api-key")
config = AdRequestConfiguration(
session_id="session-abc",
user_agent="Mozilla/5.0 (X11; Linux x86_64)",
x_forwarded_for="203.0.113.10",
)
result = await client.request_ad_or_default_async(
prompt="How can I improve user retention?",
config=config,
)
llm_response = "Your final model output here"
await client.analyse_and_report_async(
enhancement_result=result,
llm_response=llm_response,
)
await client.aclose()
asyncio.run(main())
Next steps
- Continue to Synchronous Analytics and Reporting.
- Continue to Exception for exception behavior details.
- Continue to Important and Disclaimers for critical integration caveats.