> For the complete documentation index, see [llms.txt](https://docs.kyelang.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kyelang.org/basics/models.md).

# Querying Models

Queries are expressions that are used in a variety of places; selecting & filtering models, defining edge types & assertions.

Expressions used in the global scope return tables. For example, the following commands will display different views of the `User` table

```
> User

> User[name == "Ben"]

> User{ id, name }
```

Expressions used within the scope of a table generate a column. For example, a filter expression, an assertion expression, or computed column expression.

<pre><code><strong>> User{ full_name: first_name + ' ' + last_name }
</strong></code></pre>

## Expressions

Expressions support the basic operations:

* `+ - * / %` math
* `== != >= > < <=` comparison
* `! & | ^` logical (not, and, or, xor)
* `()` parenthesis

## Selecting

Use the curly brackets after a table expression to create a new view of that type, showing only the listed columns, able to define new computed columns, or define additional assertions for that view.

```
> User {
    id,
    full_name: first_name + ' ' + last_name
    assert id > 0
  }
```

## Filtering

Use square brackets after a table expression with a list of expressions that all must be true in order to be included in the resulting table.

```
> User[
    name == "Ben"
    country == "US"
  ]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kyelang.org/basics/models.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
