{"slug": "build-end-to-end-ml-workflows-with-genie-code", "title": "Build end-to-end ML workflows with Genie Code", "summary": "Databricks detailed how its Genie Code assistant, powered by Genie Ontology and drawing on Unity Catalog and workspace context, guides data scientists through a crawl-walk-run ML lifecycle on the Databricks Platform, from a working model to automated retraining and monitoring. The walkthrough uses the Lending Club loan dataset shipped in every Databricks workspace at samples/databricks/datasets/lending-club-loan-stats, which contains 145 columns, to train a binary classifier predicting borrower default. Databricks said Genie Code works across MLflow, Feature Store and Model Serving so developers can carry work from experimentation to deployment rather than treating each stage as a separate project.", "body_md": "See how one well-framed prompt at each stage takes a raw dataset from a single-notebook experiment to a tuned, explainable, monitored production ML system on Databricks.\n\nBuilding a machine learning model is only one part of putting ML into production. Data scientists also need to engineer features, track experiments, deploy models, automate pipelines and monitor performance over time. Managing these interconnected workflows requires significant engineering effort, often across multiple tools.\n\nGenie Code helps data scientists work across the ML lifecycle using natural language. With access to Databricks tools and workspace context, it can help developers explore data, build models, identify potential issues and set up the infrastructure needed to deploy and operate them. Instead of manually connecting every component, developers can guide Genie Code through the workflow, review its decisions and iterate as they go.\n\nIn this post, we'll demonstrate that process using a loan default prediction model. Starting with a raw dataset, we'll use Genie Code to move through three stages: crawl (build a working model), walk (improve and deploy it) and run (automate retraining and monitor model health). Along the way, you'll see Genie Code act as a design partner for modeling and architecture choices, not just a code generator.\n\nGenie Code brings AI-assisted development to the Databricks Platform, combining coding capabilities with an understanding of your organization's data and business context. Powered by Genie Ontology, it can use context from Unity Catalog and your workspace to understand what data means, how assets relate and what's already been built. This helps Genie Code make more informed recommendations based on your specific environment rather than generating code in isolation.\n\nGenie Code also works across Databricks ML capabilities, including MLflow, Feature Store and Model Serving. This allows developers to build on their work as they move from experimentation to deployment and monitoring, rather than treating each stage as a separate project.\n\nThroughout the process, data scientists stay in control. They can inspect generated code, validate decisions and refine the workflow as requirements evolve.\n\nWe'll do this with a crawl, walk, run progression:\n\nWe're using raw Lending Club loan data that ships with every Databricks workspace (in `samples/databricks/datasets/lending-club-loan-stats`). Lending Club is a consumer lending marketplace. We'll use its sample loan data to train a binary classifier that predicts whether a borrower will default. The dataset contains 145 columns, including information that could introduce target leakage if used without careful feature selection.\n\nBefore writing a line of modeling code, it’s a good idea to take a second and survey what’s already in your workspace. Genie Code has access to Unity Catalog, your existing notebooks, and an entire [graph ontology](https://learn.microsoft.com/en-us/azure/databricks/genie/genie-ontology) of trusted assets in the platform, which means it can tell you what's already been built for a problem like yours. A simple prompt like this is a great way to start:\n\n*I want to build a classifier to predict loan defaults. Are there existing features or tables I could reuse, any pipelines that already clean or augment lending data, or any registered models or notebooks that tackle a similar problem?* \n\nIn larger-scale projects, taking the time to do this initial exploration can save days of work. Genie Code can surface Feature Views you can reuse instead of rebuilding, augmentation pipelines already running on similar data, and even models that already solve a comparable problem. For this walkthrough, we'll build the workflow from scratch rather than reuse existing assets, but checking what's already available is a useful first step when working with your own data.\n\n**Genie Code prompt**:\n\n*I have raw Lending Club loan data in* */Volumes/samples/databricks/datasets/lending-club-loan-stats/**. I want to build a binary classifier that predicts whether a borrower will default. Can you explore the data, engineer a proper label from the loan status field, clean up features that wouldn't be available at prediction time or are leaky, and then fit a few models to find the best one? Log everything to MLflow so I can compare runs. Use* *insert_catalog_here* *for any tables you write.*\n\nThat's it. Don’t forget to insert your catalog. I’ll walk through what it produced. If you’d like to follow along with the code, I put all of the assets and prompts in a repo [here](https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code).\n\nThe table below shows six loan statuses in the sample:\n\n| Status | Count | What it means | \n| Current | 122,469 | Loan is active, outcome unknown | \n| Fully Paid | 5,660 | Borrower repaid in full | \n| In Grace Period | 1,062 | Payment due recently, could go either way | \n| Late (31-120 days) | 1,032 | Seriously delinquent | \n| Late (16-30 days) | 415 | Delinquent | \n| Charged Off | 134 | Written off as a loss | \n\nIf you just slap a classifier on all 130k rows, you're making a critical mistake: \"Current\" loans haven't been resolved yet. You don't know if they'll default, so they are effectively unlabeled data.\n\nGenie Code caught this immediately. It excluded \"Current\" and \"In Grace Period\" loans (ambiguous), and then created a mapping for the remaining columns. This illustrates how Genie Code can apply problem-specific reasoning to label engineering rather than relying on predefined modeling steps.\n\nIt is worth pointing out that with loan data like this, you would normally split train and test by time so you don't leak the future into the past. Since this sample is a single quarter of originations, there isn't enough of a window for a temporal split to mean much, and we split randomly instead. Genie Code is great at surfacing insights like this and can flag trade-offs instead of blindly acting.\n\nIt made similarly reasonable decisions for the many potential features in front of it. Of the 145 original columns, Genie Code identified and removed:\n\n`total_pymnt`, `recoveries`, l` ast_pymnt_d`, etc.) - These exist because payments were made. At application time, they wouldn't exist.`id`, `member_id`, `url`) - No predictive value for tabular ML.\nDomain reasoning like this helps distinguish a usable model from a misleading one. Genie Code helped identify modeling decisions that could have undermined the results before training began, including unresolved labels and target leakage.\n\nGenie Code built sklearn Pipelines with ColumnTransformer:\n\n`OrdinalEncoder` for categoricals (trees split on values, ordering doesn't matter)`OneHotEncoder` + `StandardScaler` (linear models need the numeric separation)`SimpleImputer`\nWe can trace everything Genie Code did in our conversation.\n\nAs with any AI-generated code, it's important to execute and validate the results. You can also ask Genie Code to explain its decisions or revise its approach. Here, Genie Code trained three models and logged their results to MLflow, including confusion matrices and ROC curves, following established Databricks development patterns.\n\nWe've trained three models in a single notebook. Next, we'll add the feature management, tuning, interpretability and serving capabilities needed to move toward deployment.\n\nTo get there, we need:\n\nWorking with Genie Code is an iterative process. For complex tasks, it often helps to break the work into smaller steps, review the output and refine your instructions. Here, we'll combine several tasks into one prompt to demonstrate the workflow:\n\n*I built a basic loan default classifier in* *src/crawl/**, but it needs to be production-quality. I want to split the next stage into three notebooks in* *src/walk/**:*\n\n*Feature engineering: set up a Feature View so my training and inference transformations stay in sync.*\n\n*Training: run a hyperparameter search over the best model type from crawl, log all trials to MLflow.* \n\n*Interpretability: in a separate notebook, load the best model from MLflow and run SHAP to explain its predictions*\n\n*Use* *your_catalog_here.lending_club_walk* *for any feature views.*\n\nA common production ML failure is a model that receives differently transformed data at inference time than it saw during training. You clean a column one way in your training notebook, a different way in your serving pipeline, and suddenly your model cannot understand its input data.\n\nGenie Code solved this by wrapping all feature logic in a single `compute_loan_features()` function and writing the cleaned output to a Delta source table. It then registered each feature column in Unity Catalog (Databricks' `ColumnSelection` pattern), keyed on `loan_id`. The registered feature definitions support governance and discoverability, while `compute_loan_features()` remains the source of truth for how the features are computed. Reusing these definitions across training and inference helps reduce the risk of training-serving skew. The benefit extends beyond this model: reusable, governed feature definitions help teams build on existing work rather than recreate feature logic for every project.\n\nIn the initial modeling stage, we used default hyperparameters, and Random Forest technically won in terms of AUC. But its recall was near zero, which is bad: it was barely flagging any defaults. Gradient boosting has far more headroom under proper tuning; that's the model we selected for further tuning. The model tuning notebook runs an [Optuna](https://optuna.org/) hyperparameter optimization study over the `HistGradientBoostingClassifier` search space: learning rate, max depth, regularization strength, leaf sizes. With our best model, we attain the following results.\n\n| Metric | Initial Random Forest | Tuned gradient boosting | \n| Test AUC | 0.7074 | 0.7212 | \n| Test Recall | 0.0443 | 0.6215 | \n| Test F1 | 0.0831 | 0.4685 | \n\nThe tuned gradient boosting model improved AUC modestly, from 0.707 to 0.721. The larger gains were in recall and F1: recall increased from 4.4% to 62.2%, while F1 improved from 0.083 to 0.469 compared with the initial Random Forest baseline. These improvements came at the expense of some precision. The right trade-off for a lending model depends on the business costs of missed defaults and false positives.\n\nWhile this is a vast improvement on our original attempt, this would be a great place to iterate further. Finding the best trade-off between false positive and false negative rates requires business judgment and is an area where talking to Genie Code about your goals can shine.\n\nA model that performs well isn't enough in regulated industries. Lending models must be explainable. The interpretability notebook loads the best model from MLflow and runs [SHAP](https://shap.readthedocs.io/en/latest/) (SHapley Additive exPlanations) on a 1,000-row sample.\n\nThe SHAP analysis reveals which features the model relies on most. Interest rate, loan grade, and revolving utilization dominate the global importance. This makes intuitive sense: borrowers with high interest rates already got flagged as riskier by Lending Club's own underwriting. The waterfall plots for individual predictions show exactly how each feature pushed a specific loan toward or away from a default prediction.\n\nMuch like the performance measures, plots get logged as artifacts on the same MLflow run as the model, keeping explanations and predictions together.\n\nWith our tuned model and SHAP analysis in place, the next step is to deploy a Model Serving endpoint for real-time inference.\n\n*Register the best model from the walk experiment to Unity Catalog and stand up a Model Serving endpoint so I can hit it with REST calls. Put the deployment notebook in* *src/walk/04_deployment**. Also add a* *05_sample_inference* *notebook that loads the endpoint and tests running a sample of predictions on it.*\n\nThe deployment notebook does three things:\n\n`stablebox_catalog.lending_club_walk.loan_default_classifier v1`)\nThe endpoint was provisioned in under 10 minutes. Once ready, scoring a loan is your pick between an SDK call and a REST API call:\n\nModel Serving handles the serving infrastructure, so developers can deploy models behind a REST API without manually provisioning compute. Endpoints can scale to accommodate changing inference demand.\n\nThe final notebook grabs 20 random loans from the source table, sends them to the live endpoint, and compares predictions to actual outcomes.\n\nWith two prompts, we generated five notebooks. Compared with the initial Random Forest baseline, the selected and tuned gradient boosting model increased recall from about 4% to 62%. It's explainable, versioned in Unity Catalog, and serving predictions over REST.\n\nOur model is now deployed and serving predictions, but operationalizing ML also requires maintaining its performance over time. Changes in data distributions and business conditions can affect model quality, making automated workflows and ongoing monitoring essential.\n\n*I want to wrap the walk stage into a* *Declarative Automation Bundle* *(DAB) so the whole pipeline runs as an automated Databricks job. Put the bundle config in* *src/run/**. The job should:*\n\n*Run feature engineering first*\n\n*Then training (depends on step 1)*\n\n*Then deployment (depends on step 2)*\n\n*Also add a schedule so it retrains weekly. Use* *your_catalog_here.lending_club_walk* *for everything.*\n\nGenie Code produced a `databricks.yml` that connects the feature engineering, model training and deployment notebooks into an automated workflow with explicit dependencies:\n\nThe bundle also includes dev and prod targets, a weekly schedule (Monday at 6 AM), and email notifications on failure. Running `databricks bundle deploy` deploys the workflow configuration and resources. The scheduled job orchestrates the existing feature engineering, training and deployment notebooks with defined dependencies and failure notifications. Instead of manually configuring the orchestration, we used Genie Code to build on the notebooks created during experimentation and make their execution repeatable.\n\nOne caveat is that this example is configured to retrain and redeploy every week without a model promotion gate. In a real pipeline, a better configuration would have a validation step that scores the new model on a held-out set and only promotes it if it beats the current champion. For something high-stakes like credit risk, a human approval step before it goes live is also warranted. There is nothing stopping us from working through this logic with Genie Code, though I exclude the steps for brevity.\n\n*Last piece: I need to know when this model goes stale. Build a monitoring dashboard in src/run/ that shows model health, including prediction distribution over time, drift metrics, and the latest accuracy against a holdout set.*\n\n*I want to see when the input data shifts enough that I should retrain. It should be incorporated in the DAB.*\n\nWhen inference logging is enabled, inference tables can capture serving requests and responses with associated metadata. Actual outcomes, when available, must be supplied and joined separately to assess model accuracy. In this walkthrough, the monitoring notebook uses synthetic timestamps to simulate a week of inference traffic for [Data Quality Monitoring](https://docs.databricks.com/aws/en/lakehouse-monitoring/).\n\nChanges in interest rates or the borrower population can cause data drift and may affect model performance. Monitoring helps identify changes that warrant investigation and potentially retraining.\n\nLet's recap what we did in this post:\n\n| Stage | Notebooks | What it delivered | Assets | \n|---|---|---|---|\n| Crawl | 1 | Label engineering, leakage removal, 3 trained models, MLflow tracking | [https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/blob/master/src/crawl/lending_club_crawl.py](https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/blob/master/src/crawl/lending_club_crawl.py) | \n| Walk | 5 | Feature Views, Optuna tuning (14x recall), SHAP explanations, live REST endpoint | [https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/tree/master/src/walk](https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/tree/master/src/walk) | \n| Run | 1 + DAB config | Automated weekly retraining, daily drift monitoring, alerting | [https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/tree/master/src/run](https://github.com/mpkrass7/ml-crawl-walk-run-with-genie-code/tree/master/src/run) | \n\nThe walkthrough illustrates three practical benefits:\n\nThe result is a foundation for an operational ML system, built incrementally through natural-language prompts and developer review.\n\nExplore [the companion repository](https://github.com/mpkrass7/end-2-end-ml-with-genie) to follow the walkthrough in your own Databricks workspace. You can also apply the same crawl, walk, run approach to your own dataset and use Genie Code to build out each stage of the ML lifecycle.\n\nGenie Code helps data scientists build and iterate on ML workflows using natural language. It can assist with data preparation, feature engineering, model training, evaluation and deployment using Databricks capabilities.\n\nYes. Genie Code can help generate workflows for model registration, deployment, automated retraining and monitoring. In this walkthrough, it creates a Declarative Automation Bundle to orchestrate the ML pipeline and configure a recurring schedule.\n\nGenie Code can generate code that uses MLflow to track experiments, compare model performance, log artifacts and register trained models. This makes it easier to manage the transition from experimentation to deployment.\n\nGenie Code can help developers create reusable feature definitions using Databricks Feature Views. Sharing feature definitions across training and inference helps reduce the risk of inconsistencies between the data used to develop a model and the data used to generate predictions.\n\nThe walkthrough demonstrates several important components of a production ML workflow, including model serving, automation and monitoring. Real-world deployments may also require additional validation, approval gates and governance controls, particularly for high-stakes applications.\n\nSubscribe to our blog and get the latest posts delivered to your inbox.", "url": "https://wpnews.pro/news/build-end-to-end-ml-workflows-with-genie-code", "canonical_source": "https://www.databricks.com/blog/build-end-end-ml-workflows-genie-code", "published_at": "2026-12-03 19:20:07+00:00", "updated_at": "2026-12-03 20:45:39.036285+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "ai-tools", "mlops", "ai-products"], "entities": ["Databricks", "Genie Code", "Genie Ontology", "Unity Catalog", "MLflow", "Feature Store", "Model Serving", "Lending Club"], "also_reported_by": [], "takeaway": "On Databricks, prompt Genie Code to survey Unity Catalog, existing notebooks and the Genie Ontology graph for reusable Feature Views, augmentation pipelines and registered models before building, then move through crawl, walk and run stages while inspecting and validating each generated step.", "recommendation": {"advice": "Before modeling, ask Genie Code to check Unity Catalog and workspace assets for reusable Feature Views, cleaning pipelines and registered models, then review each generated step as you move from a working model to automated retraining and monitoring.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/build-end-to-end-ml-workflows-with-genie-code", "markdown": "https://wpnews.pro/news/build-end-to-end-ml-workflows-with-genie-code.md", "text": "https://wpnews.pro/news/build-end-to-end-ml-workflows-with-genie-code.txt", "jsonld": "https://wpnews.pro/news/build-end-to-end-ml-workflows-with-genie-code.jsonld"}}