---
title: Forced Decision methods for the Go SDK
slug: feature-experimentation/docs/forced-decision-methods-go
docTags: 
createdAt: 2026-08-05T20:40:00.000Z
---

These methods help test and debug various flows of your client applications by forcing users into a specific variation.

The Go SDK checks if any Forced Decision methods were implemented before making any decisions. If a matching item is found for the requested flag, the Go SDK returns the forced decision immediately ([audience conditions](docId\:UDBvr5a8WHNkyOqzPhOr9) and traffic allocations are ignored) before making normal decisions.

The Go SDK checks for forced decisions at the start of each decision process. If a matching forced decision is found, it returns the decision immediately.

- **Flag-to-Decision** – The SDK checks at the start of any decide call for the given flag.
- **Experiment-Rule-to-Decision** – The SDK checks at the start of the decision for the given experiment rule of the flag key.
- **Delivery-Rule-to-Decision** – The SDK checks at the start of the decision for the given delivery rule of the flag key.

:::hint{type="danger"}
**Warning**
You must associate your variations to a [flag rule](docId:-yq2-thNRv7-SgwCXpG90) before calling any Forced Decision methods.
:::

On forced decisions, the Go SDK fires impression events and notifications just like other normal decisions (unless disabled by the [disableDecisionEvent](docId\:BlCsg45md_3l5fQuAUQwO) option).

:::hint{type="info"}
**Note**
These forced decisions are not persistent and are cleared when the [OptimizelyUserContext](docId\:YD23vbbeambJxxmSEXUo8) is re-initialized.
:::

For information about each Forced Decision method, click on the method name:

- [\`setForcedDecision()\`](docId\:At_dXFkbnPWA2EZrLFy2c)
- [\`getForcedDecision\`](docId\:At_dXFkbnPWA2EZrLFy2c)
- [\`removeForcedDecision\`](docId\:At_dXFkbnPWA2EZrLFy2c)
- [\`removeAllForcedDecisions\`](docId\:At_dXFkbnPWA2EZrLFy2c)

### OptimizelyDecisionContext

```go
type OptimizelyDecisionContext struct {
	FlagKey string
	RuleKey string
}
```

### OptimizelyForcedDecision

```go
type OptimizelyForcedDecision struct {
	VariationKey string
}
```

## Set Forced Decision method – `setForcedDecision()`

### Version

1.8.0 or higher

### Description

Sets a forced decision (`VariationKey`) for a given `OptimizelyDecisionContext`.

### Parameters

This table lists the required and optional parameters for the Go SDK.

| Parameter                  | Type   | Description                                                                                                                                  |
| -------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\*   | Struct | An instance of \`OptimizelyDecisionContext\` with the required \`FlagKey\` and optional \`RuleKey\` for the forced decision you want to set. |
| **decision**\ \*required\* | Struct | An instance of \`OptimizelyForcedDecision\` with the required \`VariationKey\` for the forced decision you want to set.                      |

### Returns

A boolean value that indicates if setting the forced decision (`VariationKey`) was completed.

### Example

See the [Full code example section](docId\:At_dXFkbnPWA2EZrLFy2c).

## Get Forced Decision method – `getForcedDecision()`

### Version

1.8.0 or higher

### Description

Returns the forced decision (`VariationKey`) for a given `OptimizelyDecisionContext`. Returns the `OptimizelyForcedDecision` instance with `error` if there is no matching item.

### Parameters

This table lists the required and optional parameters for the Go SDK.

| Parameter                | Type   | Description                                                                                                                                  |
| ------------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\* | Struct | An instance of \`OptimizelyDecisionContext\` with the required \`FlagKey\` and optional \`RuleKey\` for the forced decision you want to get. |

### Returns

A forced decision `OptimizelyForcedDecision` instance for the context with an error if no matching item exists.

### Example

See the [Full code example section](docId\:At_dXFkbnPWA2EZrLFy2c).

## Remove Forced Decision method – `removeForcedDecision()`

### Version

1.8.0 or higher

### Description

Removes the forced decision (`VariationKey`) for a given `OptimizelyDecisionContext`.

### Parameters

This table lists the required and optional parameters for the Go SDK.

| Parameters               | Type   | Description                                                                                                                                     |
| ------------------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\* | Struct | An instance of \`OptimizelyDecisionContext\` with the required \`FlagKey\` and optional \`RuleKey\` for the forced decision you want to remove. |

### Returns

A success/failure boolean status if the forced decision (`VariationKey`) was removed.

### Example

See the [Full code example section](docId\:At_dXFkbnPWA2EZrLFy2c).

## Remove all forced decisions method - `removeAllForcedDecisions()`

### Version

1.8.0 or higher

### Description

Removes all forced decisions (`VariationKey`) for the user context.

### Parameters

This table lists the required and optional parameters for the Go SDK.

| Parameters | Type | Description |
| ---------- | ---- | ----------- |
| None       | N/A  | N/A         |

### Returns

A success/failure boolean status.

### Example

See the [Full code example section](docId\:At_dXFkbnPWA2EZrLFy2c).

## Full code example

```go
factory := &client.OptimizelyFactory{SDKKey: "sdk-key"}
if optimizely, err := factory.StaticClient(); err == nil {
  user := optimizely.CreateUserContext("test-user", map[string]interface{}{})

  flagContext := decision.OptimizelyDecisionContext{FlagKey: "flag-1"}
  flagAndABTestContext := decision.OptimizelyDecisionContext{FlagKey: "flag-1", RuleKey: "ab-test-1"}
  flagAndDeliveryRuleContext := decision.OptimizelyDecisionContext{FlagKey: "flag-1", RuleKey: "delivery-1"}
  variationAForcedDecision := decision.OptimizelyForcedDecision{VariationKey: "variation-a"}
  variationBForcedDecision := decision.OptimizelyForcedDecision{VariationKey: "variation-b"}
  variationOnForcedDecision := decision.OptimizelyForcedDecision{VariationKey: "on"}

  // set a forced decision for a flag
  success := user.SetForcedDecision(flagContext, variationAForcedDecision)
  decision := user.Decide("flag-1", nil)

  // set a forced decision for an ab-test rule
  success = user.SetForcedDecision(flagAndABTestContext, variationBForcedDecision)
  decision = user.Decide("flag-1", nil)

  // set a forced variation for a delivery rule
  success = user.SetForcedDecision(flagAndDeliveryRuleContext, variationOnForcedDecision)
  decision = user.Decide("flag-1", nil)

  // get forced variations
  if forcedDecision, err := user.GetForcedDecision(flagContext); err == nil {
    fmt.Println("[ForcedDecision] variationKey = " + forcedDecision.VariationKey)
  }

  // remove forced variations
  success = user.RemoveForcedDecision(flagAndABTestContext)
  success = user.RemoveAllForcedDecisions()
}
```

## See also

[OptimizelyUserContext](docId\:YD23vbbeambJxxmSEXUo8)
