[FEATURE] Unified LLM Observability & Interfaces — Cost Tracking, Streaming, Evaluation, and Natural Language Querying#577
Merged
gelluisaac merged 5 commits intoJul 25, 2026
Conversation
|
@dorismaduegbunam Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
| try: | ||
| async with asyncio.timeout(timeout_seconds): | ||
| # Execute raw SQL select | ||
| result = await db.execute(text(sql)) |
| budget.is_blocked = True | ||
| logger.warning( | ||
| "LLM Budget Blocked: entity %s reached limit of $%.2f (spend: $%.2f)", | ||
| entity_id, budget.limit_amount, budget.current_spend |
| # 1. Validate query safety | ||
| is_safe, violations = validate_query_safety(sql) | ||
| if not is_safe: | ||
| logger.warning("Audit Log: Blocked query validation failure: '%s'. Violations: %s", sql, violations) |
| logger.warning("Audit Log: Blocked query validation failure: '%s'. Violations: %s", sql, violations) | ||
| raise QueryValidationError(f"Query validation failed: {', '.join(violations)}") | ||
|
|
||
| logger.info("Audit Log: Executing validated query: '%s'", sql) |
| return rows | ||
|
|
||
| except asyncio.TimeoutError: | ||
| logger.error("Audit Log: Query timed out after %s seconds: '%s'", timeout_seconds, sql) |
| logger.error("Audit Log: Query timed out after %s seconds: '%s'", timeout_seconds, sql) | ||
| raise TimeoutError(f"Query execution timed out after {timeout_seconds}s limit.") | ||
| except Exception as e: | ||
| logger.error("Audit Log: Database execution error for query '%s': %s", sql, e) |
| try: | ||
| async for chunk in generator: | ||
| if self.buffer.is_aborted: | ||
| logger.info("Stream handler for session %s aborted", self.session_id) |
| yield chunk | ||
|
|
||
| except asyncio.CancelledError: | ||
| logger.info("Stream execution cancelled for session %s", self.session_id) |
| self.buffer.abort() | ||
| raise | ||
| except Exception as e: | ||
| logger.error("Exception during streaming for session %s: %s", self.session_id, e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #452
Closes #450
Closes #448
Closes #446
This PR implements a comprehensive suite of features to enhance LLM capabilities, observability, and cost control across the AstroML platform:
Key Changes
Observability & Infrastructure
LLMCostRecord) and tracking limits (LLMBudget).Streaming Response
Evaluation & Quality
Natural Language Interfaces
Web Routes & Registrations