Creating LookML Model, Views & Writing LookML
This skill guides you through the process of writing all the LookML (view
files and model files) needed to prepare for the dashboard requested by the user
during their onboarding interview, configuring the connection mapping in Looker,
validating the LookML code, and running inline queries to verify it functions
correctly.
Prerequisites & References
- Looker CLI must be installed and authenticated (Step 2 & 3).
- Looker project and BigQuery connection must be created (Step 4 & 5).
- Critical Reference: You MUST read and strictly follow the best
practices, naming requirements, and constraints in the
lookml-modeling-guidelines skill for writing and verifying all LookML
elements.
Instructions
1. Retrieve Onboarding Goal and Schema Specifications
Refer back to the onboarding goal and BigQuery exploration results established
with the user during the Step 1 (Discovery) interview in the conversation
history. You must recall: 1. The target Dashboard Goal (e.g., Sales
Overview, Support Metrics, etc.). 2. The specific GCP Project, Dataset,
and Tables (fact and dimension) agreed upon. 3. The target Metrics
(measures) and Dimensions to be used.
Note: Do not invent or guess these details. The names of your views, fields,
explores, and models must directly map to the schema and tables you discovered
in Step 1.
2. Create and Edit View Files (CLI)
For each BigQuery table required to build the target dashboard, you must write
the LookML view definition and upload it to the project:
Create the views directory: If the views/ directory does not yet
exist in the project, create it using the Looker CLI:
looker-cli project directory create {project_id} views
Generate View Content: Retrieve the table columns (from Discovery) and
write the LookML view file content locally (e.g. to
/tmp/{table_name}.view.lkml). Follow the primary key and field definitions
guidelines.
Upload the View File: Upload the file to your Looker project views
folder:
looker-cli project file create {project_id} views/{table_name}.view.lkml /tmp/{table_name}.view.lkml
Guideline Reference: You MUST consult and strictly follow the view
creation best practices in the lookml-modeling-guidelines skill
(Section 4 & 6.C) for all view definitions, primary key rules, and field
reference specifications.
3. Create/Update the Model File (CLI)
Write the LookML model definition and upload it to the project root:
Write the model LookML structure (defining explores, joins, and includes) to
a local file (e.g., /tmp/{model_name}.model.lkml).
- Specify your database connection:
connection: "{connection_name}".
- Include the specific view files required (e.g.,
include: "/views/orders.view.lkml", include: "/views/users.view.lkml"). Avoid
using broad wildcards like "/views/**/*.view.lkml" to prevent
performance bloat and compile errors.
- Critical for Dashboards: If planning to create LookML dashboards,
you MUST include them in the model file by adding
include: "/dashboards/**/*.dashboard.lookml".
- Define explores and joins.
Upload the model file to your Looker project root:
looker-cli project file create {project_id} {model_name}.model.lkml /tmp/{model_name}.model.lkml
Guideline Reference: You MUST consult and strictly follow the model
and explore best practices in the lookml-modeling-guidelines skill
(Section 6.A & 6.B) for all include declarations, explore structures, and
explicit join relationship definitions.
4. Configure Model Connection in Looker (CLI)
Map your LookML model to the allowed database connection in Looker using the
Looker CLI. This step is mandatory for Looker to register the model
configuration mapping and enable querying.
Write the model configuration payload directly to /tmp/model_config.json:
{
"name": "{model_name}",
"project_name": "{project_id}",
"allowed_db_connection_names": ["{connection_name}"]
}
Register the model configuration mapping (Mandatory Step):
looker-cli model import /tmp/model_config.json
Verify the mapping:
looker-cli model cat {model_name}
Ensure the returned JSON correctly lists your connection in
allowed_db_connection_names.
5. Validate the Project's LookML (CLI)
Validate the LookML code to ensure there are no syntax or logic errors:
Trigger project validation using the Looker CLI:
looker-cli api project validate_project {project_id}
If errors are found, fix them in your local files, upload the updated
versions using looker-cli project file update, and re-run validation until
clean.
Guideline Reference: Under our Zero-Error Policy, you are strictly
forbidden from submitting code that fails validation. Refer to
lookml-modeling-guidelines (Section 3 & 5) for detailed validation
rules and the feedback loop process.
6. Verify by Running Queries (CLI)
Test your connection and LookML model by running a verification query:
Use Discovery tools in lookml-modeling-guidelines (Section 2) to find
the fully qualified names of the dimensions and measures you defined.
Write the JSON query payload directly to /tmp/verify_query.json
(requesting your fully qualified dimension and measure, limited to 5 rows):
{
"model": "{model_name}",
"view": "{explore_name}",
"fields": ["{explore_name}.{dimension_name}", "{explore_name}.{measure_name}"],
"limit": 5
}
Execute the query using the Looker CLI:
looker-cli query runquery --file /tmp/verify_query.json --format json
Confirm that the query executes successfully and returns data without
database or SQL errors. Refer to lookml-modeling-guidelines
(Section 3) for verification guidelines.
1---2name: creating-lookml-model3description: Looker Developer Onboarding: Step 6. Creates LookML views and models based on the user's goals, maps model connections, validates LookML, and runs verification queries. Only execute this after Step 5 (Project Setup using `setting-up-looker-project`).4license: Apache-2.05---67# Creating LookML Model, Views & Writing LookML89This skill guides you through the *process* of writing all the LookML (view10files and model files) needed to prepare for the dashboard requested by the user11during their onboarding interview, configuring the connection mapping in Looker,12validating the LookML code, and running inline queries to verify it functions13correctly.1415## Prerequisites & References1617- Looker CLI must be installed and authenticated (Step 2 & 3).18- Looker project and BigQuery connection must be created (Step 4 & 5).19- **Critical Reference**: You **MUST** read and strictly follow the best20 practices, naming requirements, and constraints in the21 **`lookml-modeling-guidelines`** skill for writing and verifying all LookML22 elements.2324## Instructions2526### 1. Retrieve Onboarding Goal and Schema Specifications2728Refer back to the onboarding goal and BigQuery exploration results established29with the user during the **Step 1 (Discovery)** interview in the conversation30history. You must recall: 1. The target **Dashboard Goal** (e.g., Sales31Overview, Support Metrics, etc.). 2. The specific **GCP Project**, **Dataset**,32and **Tables** (fact and dimension) agreed upon. 3. The target **Metrics**33(measures) and **Dimensions** to be used.3435*Note: Do not invent or guess these details. The names of your views, fields,36explores, and models must directly map to the schema and tables you discovered37in Step 1.*3839### 2. Create and Edit View Files (CLI)4041For each BigQuery table required to build the target dashboard, you must write42the LookML view definition and upload it to the project:43441. **Create the `views` directory**: If the `views/` directory does not yet45 exist in the project, create it using the Looker CLI:4647 ```bash48 looker-cli project directory create {project_id} views49 ```50512. **Generate View Content**: Retrieve the table columns (from Discovery) and52 write the LookML view file content locally (e.g. to53 `/tmp/{table_name}.view.lkml`). Follow the primary key and field definitions54 guidelines.55563. **Upload the View File**: Upload the file to your Looker project views57 folder:5859 ```bash60 looker-cli project file create {project_id} views/{table_name}.view.lkml /tmp/{table_name}.view.lkml61 ```62634. **Guideline Reference**: You **MUST** consult and strictly follow the view64 creation best practices in the **`lookml-modeling-guidelines`** skill65 (Section 4 & 6.C) for all view definitions, primary key rules, and field66 reference specifications.6768### 3. Create/Update the Model File (CLI)6970Write the LookML model definition and upload it to the project root:71721. Write the model LookML structure (defining explores, joins, and includes) to73 a local file (e.g., `/tmp/{model_name}.model.lkml`).74 - Specify your database connection: `connection: "{connection_name}"`.75 - Include the specific view files required (e.g., `include:76 "/views/orders.view.lkml"`, `include: "/views/users.view.lkml"`). Avoid77 using broad wildcards like `"/views/**/*.view.lkml"` to prevent78 performance bloat and compile errors.79 - **Critical for Dashboards**: If planning to create LookML dashboards,80 you **MUST** include them in the model file by adding `include:81 "/dashboards/**/*.dashboard.lookml"`.82 - Define explores and joins.832. Upload the model file to your Looker project root:8485 ```bash86 looker-cli project file create {project_id} {model_name}.model.lkml /tmp/{model_name}.model.lkml87 ```88893. **Guideline Reference**: You **MUST** consult and strictly follow the model90 and explore best practices in the **`lookml-modeling-guidelines`** skill91 (Section 6.A & 6.B) for all include declarations, explore structures, and92 explicit join relationship definitions.9394### 4. Configure Model Connection in Looker (CLI)9596Map your LookML model to the allowed database connection in Looker using the97Looker CLI. **This step is mandatory** for Looker to register the model98configuration mapping and enable querying.991001. Write the model configuration payload directly to `/tmp/model_config.json`:101102 ```json103 {104 "name": "{model_name}",105 "project_name": "{project_id}",106 "allowed_db_connection_names": ["{connection_name}"]107 }108 ```1091102. **Register the model configuration mapping (Mandatory Step)**:111112 ```bash113 looker-cli model import /tmp/model_config.json114 ```1151163. Verify the mapping:117118 ```bash119 looker-cli model cat {model_name}120 ```121122 Ensure the returned JSON correctly lists your connection in123 `allowed_db_connection_names`.124125### 5. Validate the Project's LookML (CLI)126127Validate the LookML code to ensure there are no syntax or logic errors:1281291. Trigger project validation using the Looker CLI:130131 ```bash132 looker-cli api project validate_project {project_id}133 ```1341352. If errors are found, fix them in your local files, upload the updated136 versions using `looker-cli project file update`, and re-run validation until137 clean.1383. **Guideline Reference**: Under our **Zero-Error Policy**, you are strictly139 forbidden from submitting code that fails validation. Refer to140 **`lookml-modeling-guidelines`** (Section 3 & 5) for detailed validation141 rules and the feedback loop process.142143### 6. Verify by Running Queries (CLI)144145Test your connection and LookML model by running a verification query:1461471. Use Discovery tools in **`lookml-modeling-guidelines`** (Section 2) to find148 the fully qualified names of the dimensions and measures you defined.1492. Write the JSON query payload directly to `/tmp/verify_query.json`150 (requesting your fully qualified dimension and measure, limited to 5 rows):151152 ```json153 {154 "model": "{model_name}",155 "view": "{explore_name}",156 "fields": ["{explore_name}.{dimension_name}", "{explore_name}.{measure_name}"],157 "limit": 5158 }159 ```1601613. Execute the query using the Looker CLI:162163 ```bash164 looker-cli query runquery --file /tmp/verify_query.json --format json165 ```1661674. Confirm that the query executes successfully and returns data without168 database or SQL errors. Refer to **`lookml-modeling-guidelines`**169 (Section 3) for verification guidelines.