# AppFunctionStringValueConstraint

Artifact: [androidx.appfunctions:appfunctions](https://developer.android.com/jetpack/androidx/releases/appfunctions) [View Source](https://cs.android.com/search?q=file:androidx/appfunctions/AppFunctionStringValueConstraint.kt+class:androidx.appfunctions.AppFunctionStringValueConstraint) Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

*** ** * ** ***


```
@Retention(value = AnnotationRetention.BINARY)
@Target(allowedTargets = [AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER])
annotation AppFunctionStringValueConstraint
```

<br />

*** ** * ** ***

Specifies constraints applied on the string values for return types, parameters, or properties in app functions.

This annotation can be applied to:

- functions annotated with `@AppFunctionDeclaration` (to constrain the return value),

- parameters of `@AppFunctionDeclaration`,

- or properties within an `@AppFunctionSerializable`.

### Usage Example:

```kotlin
// Constraining a function return value:
@AppFunctionDeclaration(isDescribedByKDoc = false)
@AppFunctionStringValueConstraint(enumValues = ["LOW", "MEDIUM", "HIGH"])
fun getPriorityLevel(): String {
    // Function body
}

// Constraining a parameter:
@AppFunctionDeclaration(isDescribedByKDoc = false)
fun setMode(
    @AppFunctionStringValueConstraint(enumValues = ["AUTO", "MANUAL"])
    mode: String
) {
    // Function body
}

// Constraining a property within an AppFunctionSerializable:
@AppFunctionSerializable(isDescribedByKDoc = false)
data class AppConfig(
    @property:AppFunctionStringValueConstraint(enumValues = ["ENABLED", "DISABLED"])
    val featureFlag: String
)
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionStringValueConstraint#AppFunctionStringValueConstraint(kotlin.Array,kotlin.Array,kotlin.String)( enumValues: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, patternMatchers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionPatternMatcher>, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionStringValueConstraint#enumValues()` The list of allowed string values for the annotated element. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionStringValueConstraint#format()` The format description for string values (e.g. `"uri"`). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionPatternMatcher>` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionStringValueConstraint#patternMatchers()` The patterns that string values must match. |

## Public constructors

### AppFunctionStringValueConstraint

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
AppFunctionStringValueConstraint(
    enumValues: Array<String> = [],
    patternMatchers: Array<AppFunctionPatternMatcher> = [],
    format: String = ""
)
```

## Public properties

### enumValues

```
val enumValues: Array<String>
```

The list of allowed string values for the annotated element.

These values are communicated to the agent or framework that interprets or invokes the `@AppFunctionDeclaration`. If any of the values carry special meaning (e.g., `"AUTO"` means automatic mode), such meanings should be documented clearly in the corresponding property, parameter, or function return KDoc.

### format

```
val format: String
```

The format description for string values (e.g. `"uri"`). An empty string indicates no format description is set.

### patternMatchers

```
val patternMatchers: Array<AppFunctionPatternMatcher>
```

The patterns that string values must match. A value is valid if it matches any of the patterns. An empty array indicates no pattern constraint is applied.

Each pattern is translated to a `https://developer.android.com/reference/android/os/PatternMatcher.html` in `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionStringTypeMetadata#patternMatchers()`.

**Important:** Patterns are not validated at compile time. If `https://developer.android.com/reference/android/os/PatternMatcher.html` rejects any pattern (for example, a malformed `https://developer.android.com/reference/android/os/PatternMatcher.html#PATTERN_ADVANCED_GLOB`), the function using it is omitted from agents' search results. If the pattern is on a property of an `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionSerializable`, all of the app's functions are omitted.