> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ionworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate SQL filter from natural language using AI

> Generate a SQL WHERE clause from a natural language description using AI.

This endpoint uses a language model to convert natural language descriptions
like "steps lasting more than an hour" into SQL WHERE clauses like
"duration_s >= 3600".

The AI also determines whether to use "step" or "cycle" match mode based
on the user's intent.

The generated SQL is validated against the specified measurement to ensure
it is syntactically correct. If validation fails, the AI will retry.

Returns:
- sql_where_clause: The generated SQL WHERE clause
- match_mode: "step" or "cycle"
- explanation: Brief explanation of what the filter does



## OpenAPI

````yaml https://api.ionworks.com/openapi.json post /cell_measurements/filter-steps/generate
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.ionworks.com
    description: Production
security: []
paths:
  /cell_measurements/filter-steps/generate:
    post:
      tags:
        - Cell Measurements
      summary: Generate SQL filter from natural language using AI
      description: >-
        Generate a SQL WHERE clause from a natural language description using
        AI.


        This endpoint uses a language model to convert natural language
        descriptions

        like "steps lasting more than an hour" into SQL WHERE clauses like

        "duration_s >= 3600".


        The AI also determines whether to use "step" or "cycle" match mode based

        on the user's intent.


        The generated SQL is validated against the specified measurement to
        ensure

        it is syntactically correct. If validation fails, the AI will retry.


        Returns:

        - sql_where_clause: The generated SQL WHERE clause

        - match_mode: "step" or "cycle"

        - explanation: Brief explanation of what the filter does
      operationId: generate_step_filter_cell_measurements_filter_steps_generate_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateFilterRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateFilterResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    GenerateFilterRequest:
      properties:
        prompt:
          type: string
          title: Prompt
        measurement_id:
          type: string
          title: Measurement Id
        current_sql:
          anyOf:
            - type: string
            - type: 'null'
          title: Current Sql
      type: object
      required:
        - prompt
        - measurement_id
      title: GenerateFilterRequest
      description: Request body for AI-powered SQL filter generation.
    GenerateFilterResponse:
      properties:
        sql_where_clause:
          type: string
          title: Sql Where Clause
        match_mode:
          type: string
          title: Match Mode
        explanation:
          type: string
          title: Explanation
      type: object
      required:
        - sql_where_clause
        - match_mode
        - explanation
      title: GenerateFilterResponse
      description: Response body for AI-powered SQL filter generation.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````