To create a workflow, you use the *Workflows syntax* to define the
steps you want and their order of execution. For more information about creating
workflows, see [Create and manage workflows](https://docs.cloud.google.com/workflows/docs/creating-updating-workflow).

For other functions available in addition to the core syntax, refer to the
[Standard library](https://docs.cloud.google.com/workflows/docs/reference/stdlib/overview) and
[Connectors](https://docs.cloud.google.com/workflows/docs/reference/googleapis) references.

## File structure

Workflow source files have the following characteristics:

- They contain only one [main workflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows#main-block).
- They might contain [subworkflows](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows).
- They are either a valid [YAML](https://yaml.org/) or
  [JSON](https://json.org/) file.

  Code samples are provided in both YAML and the equivalent JSON.

  > [!NOTE]
  > **Note:** YAML indentation is meaningful and should be at least two spaces per indentation level. Insufficient indentation can cause errors, and a new level should be at least two spaces in from the *start of the text* in the previous line. For more details, see [Troubleshoot issues](https://docs.cloud.google.com/workflows/docs/troubleshooting#indentation).

## Search the syntax

You can search the Workflows syntax for its reserved words and other
details. To see examples of the syntax in action, see the
[cheat sheet](https://docs.cloud.google.com/workflows/docs/reference/syntax/syntax-cheat-sheet).

| Reserved word | Description | Use with | See also | Examples |
|---|---|---|---|---|
| ### `args` | Pass arguments and their values when calling a function that accepts parameters. | `call` steps | `call` `result` | - [Calls](https://docs.cloud.google.com/workflows/docs/reference/syntax/calls) |
| ### `assign` | Set the value of a variable. | --- | --- | - [Assign variables](https://docs.cloud.google.com/workflows/docs/reference/syntax/variables#assign-step) |
| ### `branches` | Execute parallel branches concurrently and the steps in each branch sequentially. | `steps` | `parallel` | - [Execute parallel steps](https://docs.cloud.google.com/workflows/docs/execute-parallel-steps) - [Parallel steps](https://docs.cloud.google.com/workflows/docs/reference/syntax/parallel-steps) - [Replace experimental function with parallel step](https://docs.cloud.google.com/workflows/docs/migrate-function-to-parallel) |
| ### `break` | Terminate iteration of a `for` loop. | `next` in `for` loops | `continue` | - [Use break/continue in a loop](https://docs.cloud.google.com/workflows/docs/reference/syntax/iteration#break-in-loop) |
| ### `call` | Run a function and return a result. | --- | `args` `result` | - [Calls](https://docs.cloud.google.com/workflows/docs/reference/syntax/calls) |
| ### `condition` | Provide an expression to control if a step is executed (the first condition to evaluate as true). | `switch` | --- | - [Conditions](https://docs.cloud.google.com/workflows/docs/reference/syntax/conditions) |
| ### `continue` | Terminate the current iteration of a `for` loop and continue with the next iteration. | `next` in `for` loops | `break` | - [Use break/continue in a loop](https://docs.cloud.google.com/workflows/docs/reference/syntax/iteration#break-in-loop) |
| ### `end` | Stop a workflow's execution without returning a value. | `next` | --- | - [Complete the execution of a workflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/completing) |
| ### `except` | Catch and handle errors thrown during a workflow execution. | `try` | `retry` | - [Catch errors](https://docs.cloud.google.com/workflows/docs/reference/syntax/catching-errors) |
| `for` | Iterate over a sequence of numbers or through a collection of data, such as a list or map. | `steps` | --- | - [Iteration](https://docs.cloud.google.com/workflows/docs/reference/syntax/iteration) |
| ### `main` | Define your main workflow. If a workflow has a subworkflow, or to receive runtime arguments, there must be a `main` block. | Subworkflows | --- | - [Main workflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/main) |
| ### `next` | Define what step Workflows should execute next. | --- | `break` `continue` | - [Jumps](https://docs.cloud.google.com/workflows/docs/reference/syntax/jumps) |
| ### `parallel` | Execute two or more steps concurrently. | `branches` `for` loops `steps` | --- | - [Execute parallel steps](https://docs.cloud.google.com/workflows/docs/execute-parallel-steps) - [Parallel steps](https://docs.cloud.google.com/workflows/docs/reference/syntax/parallel-steps) - [Replace experimental function with parallel step](https://docs.cloud.google.com/workflows/docs/migrate-function-to-parallel) |
| ### `params` | Accept workflow execution arguments, or arguments passed to a subworkflow. | Subworkflows | `main` | - [Pass runtime arguments in an execution request](https://docs.cloud.google.com/workflows/docs/passing-runtime-arguments) - [Runtime arguments](https://docs.cloud.google.com/workflows/docs/reference/syntax/runtime-args) - [Subworkflows](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows) |
| ### `raise` | Raise custom errors. | --- | `except` `retry` `try` | - [Raise errors](https://docs.cloud.google.com/workflows/docs/reference/syntax/raising-errors) |
| ### `result` | Assign the result from a call to this variable. | `call` steps | `args` | - [Assign responses from a call](https://docs.cloud.google.com/workflows/docs/reference/syntax/calls#assign_responses_from_a_call) - [Store result from a call in a variable](https://docs.cloud.google.com/workflows/docs/reference/syntax/variables#store-result) |
| ### `retry` | Define the retry behavior and the number of retry attempts. | `try` | --- | - [Retry steps](https://docs.cloud.google.com/workflows/docs/reference/syntax/retrying) |
| ### `return` | Stop a workflow's execution and return a value or expression. | --- | --- | - [Complete the execution of a workflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/completing) |
| ### `steps` | Nest a series of steps. | `branches` `for` loops Subworkflows `try` | `main` | - [Iteration](https://docs.cloud.google.com/workflows/docs/reference/syntax/iteration) - [Nested steps](https://docs.cloud.google.com/workflows/docs/reference/syntax/steps#embedded-steps) - [Subworkflows](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows) |
| ### `switch` | Allow the value of an expression to control the flow of a workflow's execution. | --- | `condition` | - [Conditions](https://docs.cloud.google.com/workflows/docs/reference/syntax/conditions) |
| ### `try` | Define a list of steps to retry if an error is raised, or catch and handle the error. | --- | `except` `retry` | - [Catch errors](https://docs.cloud.google.com/workflows/docs/reference/syntax/catching-errors) - [Retry steps](https://docs.cloud.google.com/workflows/docs/reference/syntax/retrying) |

### Example: `args`

### YAML

```yaml
  - STEP_NAME:
      call: ...
      args:
      ...
      result: VARIABLE
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "call": ...,
        "args": {
          ...
        },
        "result": "VARIABLE"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `assign`

### YAML

```yaml
  - STEP_NAME:
      assign:
          - VARIABLE_NAME: VALUE
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "assign": [
          {
            "VARIABLE_NAME": "VALUE"
          }
        ]
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `branches`

### YAML

```yaml
  - PARALLEL_STEP_NAME:
      parallel:
          ...
          branches:
            - BRANCH_NAME_A:
                steps:
                    ...
            - BRANCH_NAME_B:
                steps:
                    ...
  
```

### JSON

```json
   [
    {
      "PARALLEL_STEP_NAME": {
        "parallel": {
          ...
          "branches": [
            {
              "BRANCH_NAME_A": {
                "steps":
                     ...
              }
            },
            {
              "BRANCH_NAME_B": {
                "steps":
                     ...
              }
            }
          ]
        }
      }
    }
  ]
  
```
<button class="devsite-dialog-close">OK</button>

### Example: `break`

### YAML

```yaml
  - FOR_LOOP_STEP_NAME_A:
      for:
          value: LOOP_VARIABLE_NAME_A
          in: ${LIST_EXPRESSION_A}    # or simply in: LIST_DEFINITION
          steps:
              - STEP_NAME_A:
                  next: continue
  - FOR_LOOP_STEP_NAME_B:
      for:
          value: LOOP_VARIABLE_NAME_B
          range: [${BEGIN_EXPRESSION}, ${END_EXPRESSION}]
          steps:
              - STEP_NAME_B:
                  next: break
```

### JSON

```json
  [
    {
      "FOR_LOOP_STEP_NAME_A": {
        "for": {
          "value": "LOOP_VARIABLE_NAME_A",
          "in": "${LIST_EXPRESSION_A}",
          "steps": [
            {
              "STEP_NAME_A": {
                "next": "continue"
              }
            }
          ]
        }
      }
    },
    {
      "FOR_LOOP_STEP_NAME_B": {
        "for": {
          "value": "LOOP_VARIABLE_NAME_B",
          "range": [
            "${BEGIN_EXPRESSION}",
            "${END_EXPRESSION}"
          ],
          "steps": [
            {
              "STEP_NAME_B": {
                "next": "break"
              }
            }
          ]
        }
      }
    }
  ]
```
<button class="devsite-dialog-close">OK</button>

### Example: `call`

### YAML

```yaml
  - STEP_NAME:
      call: ...
      args:
      ...
      result: VARIABLE
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "call": ...,
        "args": {
          ...
        },
        "result": "VARIABLE"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `condition`

### YAML

```yaml
  - STEP_NAME_A:
      switch:
          - condition: ${EXPRESSION_A}
            next: STEP_NAME_B
          - condition: ${EXPRESSION_B}
            next: STEP_NAME_C
          - condition: true
            next: STEP_NAME_C
      next: STEP_NAME_D
  
```

### JSON

```json
  [
    {
      "STEP_NAME_A": {
        "switch": [
          {
            "condition": "${EXPRESSION_A}",
            "next": "STEP_NAME_B"
          },
          {
            "condition": "${EXPRESSION_B}",
            "next": "STEP_NAME_C"
          }
          {
            "condition": true,
            "next": "STEP_NAME_C"
          }
        ],
        "next": "STEP_NAME_D"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `continue`

### YAML

```yaml
  - FOR_LOOP_STEP_NAME_A:
      for:
          value: LOOP_VARIABLE_NAME_A
          in: ${LIST_EXPRESSION_A}    # or simply in: LIST_DEFINITION
          steps:
              - STEP_NAME_A:
                  next: continue
  - FOR_LOOP_STEP_NAME_B:
      for:
          value: LOOP_VARIABLE_NAME_B
          range: [${BEGIN_EXPRESSION}, ${END_EXPRESSION}]
          steps:
              - STEP_NAME_B:
                  next: break
```

### JSON

```json
  [
    {
      "FOR_LOOP_STEP_NAME_A": {
        "for": {
          "value": "LOOP_VARIABLE_NAME_A",
          "in": "${LIST_EXPRESSION_A}",
          "steps": [
            {
              "STEP_NAME_A": {
                "next": "continue"
              }
            }
          ]
        }
      }
    },
    {
      "FOR_LOOP_STEP_NAME_B": {
        "for": {
          "value": "LOOP_VARIABLE_NAME_B",
          "range": [
            "${BEGIN_EXPRESSION}",
            "${END_EXPRESSION}"
          ],
          "steps": [
            {
              "STEP_NAME_B": {
                "next": "break"
              }
            }
          ]
        }
      }
    }
  ]
```
<button class="devsite-dialog-close">OK</button>

### Example: `end`

### YAML

```yaml
  - STEP_NAME:
      ...
      next: end
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        ...
        "next": "end"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `except`

### YAML

```yaml
  - STEP_NAME:
     try:
         call: http.get
         ...
     except:
         as: ERROR_MAP
         steps:
             ...
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "try": {
          "call": "http.get"
          ...
        },
        "except": {
          "as": "ERROR_MAP",
          "steps":
              ...
        }
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `for`

### YAML

```yaml
  - FOR_LOOP_STEP_NAME:
      for:
          value: LOOP_VARIABLE_NAME
          index: INDEX_VARIABLE_NAME
          in: ${LIST_EXPRESSION}
          steps:
              - STEP_NAME_A:
                ...
```

### JSON

```json
  [
    {
      "FOR_LOOP_STEP_NAME": {
        "for": {
          "value": "LOOP_VARIABLE_NAME",
          "index": "INDEX_VARIABLE_NAME",
          "in": "${LIST_EXPRESSION}",
          "steps": [
            {
              "STEP_NAME_A":
                ...
            }
          ]
        }
      }
    }
  ]
```
<button class="devsite-dialog-close">OK</button>

### Example: `main`

### YAML

```yaml
  main:
      params: [MAP_NAME]
      steps:
          - STEP_NAME:
              ...
          ...
  
```

### JSON

```json
    {
      "main": {
        "params": [
          "MAP_NAME"
        ],
        "steps": [
          {
            "STEP_NAME": {
              ...
            }
          },
          ...
        ]
      }
    }
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `next`

### YAML

```yaml
  - STEP_NAME:
      ...
      next: STEP_NAME_TO_JUMP_TO
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        ...
        "next": "STEP_NAME_TO_JUMP_TO"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `params`

### YAML

```yaml
   main:
       steps:
           - STEP_NAME:
               call: SUBWORKFLOW_NAME
               args:
                   ARG_1: VALUE_1
                   ARG_2: VALUE_2
                   ...
               result: OUTPUT_VARIABLE
   SUBWORKFLOW_NAME:
        params: [PARAMETER_1,PARAMETER_2...]
        steps:
            - step_1:
            ...
  
```

### JSON

```json
  {
    "main": {
      "steps": [
        {
          "STEP_NAME": {
            "call": "SUBWORKFLOW_NAME",
            "args": {
              "ARG_1": "VALUE_1",
              "ARG_2": "VALUE_2"
            },
            "result": "OUTPUT_VARIABLE"
          }
        }
      ]
    },
    "SUBWORKFLOW_NAME": {
      "params": ["PARAMETER_1,PARAMETER_2"...],
      "steps": [
        {
          "step_1":
          ...
        }
      ]
    }
  }
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `parallel`

### YAML

```yaml
  - PARALLEL_STEP_NAME:
      parallel:
          exception_policy: POLICY
          shared: [VARIABLE_A, VARIABLE_B, ...]
          BRANCHES_OR_FOR:
             ...
```

### JSON

```json
  [
    {
      "PARALLEL_STEP_NAME": {
        "parallel": {
          "exception_policy": "POLICY",
          "shared": [
            "VARIABLE_A",
            "VARIABLE_B",
            ...
          ],
          "BRANCHES_OR_FOR":
          ...
        }
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `raise`

### YAML

```yaml
  - step_a:
      raise: "Something went wrong."
  
```

### JSON

```json
  [
    {
      "step_a": {
        "raise": "Something went wrong."
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `result`

### YAML

```yaml
  - STEP_NAME:
      call: ...
      args:
      ...
      result: VARIABLE
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "call": ...,
        "args":
        ...,
        "result": "VARIABLE"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `retry`

### YAML

```yaml
  - step_name:
      try:
          steps:
              ...
      retry: RETRY_POLICY
          predicate: RETRY_PREDICATE
          max_retries: NUMBER_OF_RETRIES
          backoff:
              initial_delay: DELAY_SECONDS
              max_delay: MAX_DELAY_SECONDS
              multiplier: DELAY_MULTIPLIER
  
```

### JSON

```json
  [
    {
      "step_name": {
        "try": {
           "steps": [
               ...
    ]
        },
        "retry": "RETRY_POLICY"
          "predicate": "RETRY_PREDICATE",
          "max_retries": NUMBER_OF_RETRIES,
          "backoff": {
            "initial_delay": DELAY_SECONDS,
            "max_delay": MAX_DELAY_SECONDS,
            "multiplier": DELAY_MULTIPLIER
          }
        }
      }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `return`

### YAML

```yaml
  - STEP_NAME:
      ...
      return: ${VARIABLE}
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        ...
        "return": "${VARIABLE}"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `steps`

### YAML

```yaml
  - STEP_NAME:
    steps:
      - STEP_NAME_1:
          steps:
              - STEP_NAME_A:
                  ...
              - STEP_NAME_B:
                  ...
      - STEP_NAME_2:
          steps:
              - STEP_NAME_C:
                  ...
  
```

### JSON

```json
    {
      STEP_NAME: {
      "steps": [
        {
          STEP_NAME_1: {
            "steps": [
              {
                STEP_NAME_A:
                  ...
              },
              {
                STEP_NAME_B:
                  ...
              }
            ]
          }
        },
        {
          STEP_NAME_2: {
            "steps": [
              {
                STEP_NAME_C:
                  ...
              }
            ]
          }
        }
      ]
    }
  }
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `switch`

### YAML

```yaml
  - STEP_NAME_A:
      switch:
          - condition: ${EXPRESSION_A}
            next: STEP_NAME_B
          - condition: ${EXPRESSION_B}
            next: STEP_NAME_C
          - condition: true
            next: STEP_NAME_C
      next: STEP_NAME_D
  
```

### JSON

```json
  [
    {
      "STEP_NAME_A": {
        "switch": [
          {
            "condition": "${EXPRESSION_A}",
            "next": "STEP_NAME_B"
          },
          {
            "condition": "${EXPRESSION_B}",
            "next": "STEP_NAME_C"
          }
          {
            "condition": true,
            "next": "STEP_NAME_C"
          }
        ],
        "next": "STEP_NAME_D"
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `try`

### YAML

```yaml
  - STEP_NAME:
     try:
         call: http.get
         ...
     except:
         as: ERROR_MAP
         steps:
             ...
  
```

### JSON

```json
  [
    {
      "STEP_NAME": {
        "try": {
          "call": "http.get"
          ...
        },
        "except": {
          "as": "ERROR_MAP",
          "steps":
              ...
        }
      }
    }
  ]
    
```
<button class="devsite-dialog-close">OK</button>

### Example: `stub`

<br />

<br />

<button class="devsite-dialog-close">OK</button>

## Using code samples

For all samples that communicate with other Google Cloud resources, your
workflow must be associated with a service account that has sufficient
privileges to access those resources. To learn more about granting roles to
service accounts, see
[Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).
To learn how to change the service account associated with a workflow, see
[update a workflow](https://docs.cloud.google.com/workflows/docs/creating-updating-workflow#updating_a_workflow).
For more information about authentication, see
[Grant a workflow permission to access Google Cloud resources](https://docs.cloud.google.com/workflows/docs/authentication).

Some samples might require that you first enable a Google Cloud API.
Learn more about [listing services](https://docs.cloud.google.com/service-usage/docs/list-services) and
[enabling services](https://docs.cloud.google.com/service-usage/docs/enable-disable).

> [!CAUTION]
> **Caution:** Some samples use placeholder URLs for Google Cloud resources and external APIs. Because of this, **samples in this reference might not
> execute without modifications**. When a sample includes the URL for a Cloud Run functions function, a Cloud Run app, or an API, you must replace that URL with the URL of your own function, app, or API.

See [all Workflows code samples](https://docs.cloud.google.com/workflows/docs/samples).

## Notation key

| Notation | Description |
|---|---|
| `[]` Square brackets | Optional; if the brackets themselves must be typed, this is indicated |
| `{}` Braces | Required |
| `|` Vertical bar | Separator for mutually exclusive items; choose one |
| `...` Ellipsis | Items that can be repeated; or indicates an omission to improve clarity and shorten the length of the example |