AI Analyst is a Streamlit-based workspace that helps analytics teams turn weekly business reviews into actionable insights. The app collects business context, generates focused Text2SQL prompts, validates query outputs, and turns findings into an executive-ready narrative powered by OpenAI or Azure OpenAI.
- Guided workflow – Capture the business brief, define KPIs, and follow a structured set of steps to keep investigations on track.
- Text2SQL assistance – Generate compact SQL prompts that respect row and column limits for safer LLM execution.
- Result validation – Upload tabular outputs (CSV/XLSX) for automated quality checks before drafting a report.
- Automated storytelling – Produce an executive summary, key findings, and follow-up questions without manual formatting.
AI-analyst/
├── app.py # Streamlit UI and workflow orchestration
├── analysis_engine.py # Initial & follow-up question generation
├── data_manager.py # Data validation and insight extraction helpers
├── report_generator.py # Report assembly using LLM prompts
├── config.py # Directory setup and runtime configuration
├── utils.py # Shared utilities (env loading, formatting, etc.)
├── text2sql/ # Helpers for schema extraction and SQL generation
├── Business Logic.md # Business playbook used by the app
├── Analysis Task.md # Default analysis brief consumed by the LLM
├── dwh_schema.txt # Sanitised warehouse schema for Text2SQL prompts
└── requirements.txt # Python dependencies
Generated artefacts such as uploaded data, reports, or cached prompts are stored in data/, temp/, and output/ (created on demand).
flowchart LR
A[Streamlit UI<br/>app.py] -->|collects prompts & uploads| B[Analysis Engine\nanalysis_engine.py]
B -->|generates tasks/questions| C[Data Manager\ndata_manager.py]
C -->|validates tabular outputs| D[Report Generator\nreport_generator.py]
B -->|constructs schema briefs| E[Text2SQL Toolkit\ntext2sql/]
E -->|optional SQL execution| F[(Warehouse / CSV exports)]
subgraph Shared Utilities
G[config.py]
H[utils.py]
end
A -.-> G
B -.-> H
C -.-> H
D -.-> H
- Streamlit UI (
app.py) drives the five-step workflow, gathers the business brief, and routes user inputs to the backend modules. - Analysis Engine (
analysis_engine.py) turns the brief into initial and follow-up LLM prompts, normalising instructions for the report generator and Text2SQL helper. - Data Manager (
data_manager.py) inspects uploaded CSV/XLSX files, surfaces anomalies, and synthesises descriptive statistics for the reporting layer. - Report Generator (
report_generator.py) assembles an executive narrative—summary, findings, actions—using the vetted metrics from the previous steps. - Text2SQL toolkit (
text2sql/) is an optional companion. It refines schema excerpts, crafts bounded SQL queries, and can run them when Azure Federated Token auth is configured. - Shared utilities (
config.py,utils.py) provide filesystem setup, environment loading, and helper routines used across the workflow.
- Provide context – Populate or edit the prompts in
Business Logic.mdandAnalysis Task.mdinside the Streamlit UI. The analysis engine uses them to seed questions for the week. - Define data slices – Upload a sanitised schema excerpt (for example
dwh_schema.txt) so Text2SQL knows which tables and columns can be queried safely. - Generate questions – The LLM produces bounded SQL prompts that respect row and column limits. Analysts can copy them into their warehouse or trigger the optional execution helper.
- Validate results – Drop CSV/XLSX exports into the app. The data manager checks schemas, missing values, and unusual deltas before allowing reporting to proceed.
- Publish insights – The report generator converts validated findings into an executive summary with key takeaways and recommended next steps.
Each module is intentionally decoupled so you can swap providers (for example, replace Azure OpenAI with standard OpenAI) or bypass the Text2SQL helpers entirely while keeping the Streamlit workflow intact.
- Python 3.9+
- An OpenAI API key or Azure OpenAI resource with a deployed GPT-4o compatible model
- Basic familiarity with Streamlit and environment variables
-
Install dependencies
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Configure environment variables
- Copy
.env.exampleto.envand populate the values with your own credentials. - For Azure OpenAI supply
AZURE_OPENAI_ENDPOINT,AZURE_OPENAI_DEPLOYMENT, andAZURE_OPENAI_API_VERSION. - For non-Azure OpenAI set
OPENAI_API_KEYand optionallyOPENAI_MODEL. - If you plan to execute SQL directly from the helper scripts, also populate
SQL_SERVER,SQL_DATABASE, andSQL_DRIVER.
- Copy
-
Run the Streamlit app
streamlit run app.py
- Business context – Paste or edit the contents of
Business Logic.mdandAnalysis Task.mdinside the app to align the investigation with your company’s goals. - Generate SQL prompts – Provide relevant schema excerpts (e.g., from
dwh_schema.txt) and let the app craft bounded Text2SQL prompts you can run in your query editor. - Validate query results – Upload CSV/XLSX exports; the app checks for schema mismatches, empty tables, and unusual values before moving on.
- Iterate with follow-up questions – Use the generated prompts and insights to refine the analysis.
- Produce the report – Trigger the report generator to create an executive summary, key findings, recommended actions, and optional efficiency metrics.
- Update
Business Logic.mdwith your KPI definitions, guardrails, and decision criteria. - Adapt
Analysis Task.mdto reflect the cadence or objective of the current review. - Replace
dwh_schema.txtwith a non-sensitive snapshot of your warehouse schema so the Text2SQL prompts stay relevant.
.gitignoreexcludes local.envfiles, caches, and generated artefacts.utils.load_credentials_from_envreads variables from the environment or.envwithout storing secrets elsewhere.- Keep production credentials out of the repository—use secret managers or deployment pipelines in production setups.
- The
text2sql/.env.examplefile mirrors the root template so Text2SQL experiments stay local and secret-free.
- Missing credentials: the Streamlit UI will prompt you to review your
.envconfiguration before enabling LLM calls. - Large uploads: keep tables small (≤50 rows, ≤8 columns) for the best LLM performance and lower latency.
- Verbose logging: run
streamlit run app.py --logger.level=debugto inspect request/response payloads when debugging.
This project is distributed for internal enablement. Add your organisation’s preferred licence if you intend to share it publicly.