> ## 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.

# Validate Expression Endpoint

> Validate a custom variable expression against a model.

Checks syntax, variable/parameter references, and cycle detection.
Accepts either ``model_id`` (for existing models) or ``config`` (for
models being created).

Parameters
----------
request : ValidateExpressionRequest
    Expression plus either model_id or config, and optional existing
    custom variables.
model_repo : ModelRepository
    Injected model repository.

Returns
-------
ValidationResult
    Validation results including errors, warnings, and references.



## OpenAPI

````yaml https://api.ionworks.com/openapi.json post /variables/validate-expression
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.ionworks.com
    description: Production
security: []
paths:
  /variables/validate-expression:
    post:
      tags:
        - variables
      summary: Validate Expression Endpoint
      description: |-
        Validate a custom variable expression against a model.

        Checks syntax, variable/parameter references, and cycle detection.
        Accepts either ``model_id`` (for existing models) or ``config`` (for
        models being created).

        Parameters
        ----------
        request : ValidateExpressionRequest
            Expression plus either model_id or config, and optional existing
            custom variables.
        model_repo : ModelRepository
            Injected model repository.

        Returns
        -------
        ValidationResult
            Validation results including errors, warnings, and references.
      operationId: validate_expression_endpoint_variables_validate_expression_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateExpressionRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/src__services__variable_validation_service__ValidationResult
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    ValidateExpressionRequest:
      properties:
        expression:
          type: string
          title: Expression
        model_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Id
        config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Config
        existing_custom_variables:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Existing Custom Variables
        new_var_name:
          anyOf:
            - type: string
            - type: 'null'
          title: New Var Name
      type: object
      required:
        - expression
      title: ValidateExpressionRequest
      description: Request body for validating a custom variable expression.
    src__services__variable_validation_service__ValidationResult:
      properties:
        valid:
          type: boolean
          title: Valid
        json_value:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Json Value
        referenced_variables:
          items:
            $ref: '#/components/schemas/ReferencedVariable'
          type: array
          title: Referenced Variables
          default: []
        parameters:
          items:
            $ref: '#/components/schemas/ReferencedParameter'
          type: array
          title: Parameters
          default: []
        errors:
          items:
            type: string
          type: array
          title: Errors
          default: []
        warnings:
          items:
            type: string
          type: array
          title: Warnings
          default: []
      type: object
      required:
        - valid
      title: ValidationResult
      description: Result of validating a custom variable expression.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ReferencedVariable:
      properties:
        name:
          type: string
          title: Name
        exists:
          type: boolean
          title: Exists
        source:
          type: string
          title: Source
      type: object
      required:
        - name
        - exists
        - source
      title: ReferencedVariable
      description: A model or custom variable referenced by a CoupledVariable node.
    ReferencedParameter:
      properties:
        name:
          type: string
          title: Name
        exists:
          type: boolean
          title: Exists
        similar_existing:
          items:
            type: string
          type: array
          title: Similar Existing
          default: []
      type: object
      required:
        - name
        - exists
      title: ReferencedParameter
      description: A Parameter node found in the expression.
    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

````