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

# AI Function Generator

> Generate validation rules, transforms, virtual columns, and regex patterns using plain-language instructions.

The **AI Function Generator** in CSVbox helps you create JavaScript functions and regex patterns without writing code manually. Describe what you want in plain English, and CSVbox generates compatible logic for your importer automatically.

AI generation is available across:

* Validation Functions
* Virtual Columns
* Data Transforms
* Regex Column Type

Use it to build advanced import logic faster, reduce manual coding, and simplify complex validation or transformation workflows.

## How it works

<Steps>
  <Step title="Open a supported editor">
    Open a supported editor in CSVbox.
  </Step>

  <Step title="Click Generate">
    Click the **Generate** button.
  </Step>

  <Step title="Describe the logic you want">
    Describe the logic in plain language. CSVbox generates compatible JavaScript or regex code.
  </Step>

  <Step title="Review the generated output">
    Review the output. All generated code remains fully editable before saving.
  </Step>

  <Step title="Insert and save the function">
    Insert the code and save the function.
  </Step>
</Steps>

## Supported features

| Feature | Generates |
| - | - |
| Validation Functions | JavaScript validation logic |
| Virtual Columns | JavaScript computed column logic |
| Data Transforms | JavaScript transformation logic |
| Regex Column Type | Regular expression patterns |

## Writing better prompts

The quality of the generated output depends heavily on how clearly you describe the requirement.

For best results:

* Mention exact column names when possible.
* Clearly describe the expected output.
* Include formatting requirements.
* Add examples for complex logic.
* Focus on one task at a time.
* Avoid vague instructions.

## AI generator for validation functions

Generate validation rules from plain-language descriptions instead of writing JavaScript validation logic by hand.

Useful for:

* Email validation
* Phone number validation
* Date validation
* Required field checks
* Cross-column validation
* Business-specific validation rules

### Example prompts

#### Email validation

**Prompt**

```
Validate that email addresses contain a valid @ symbol and domain
```

**Expected behavior**

* `"user@example.com"` → valid
* `"user@"` → invalid

#### Phone number validation

**Prompt**

```
Ensure phone numbers contain exactly 10 digits after removing special characters
```

**Expected behavior**

* `"(555) 123-4567"` → valid
* `"123-456"` → invalid

#### Date validation

**Prompt**

```
Check that dates are in YYYY-MM-DD format and are not future dates
```

**Expected behavior**

* `"2023-12-25"` → valid
* `"12/25/2023"` → invalid

#### Cross-column validation

**Prompt**

```
Ensure end_date is greater than start_date
```

**Expected behavior**

* `start_date="2023-01-01", end_date="2023-12-31"` → valid
* `start_date="2023-12-31", end_date="2023-01-01"` → invalid

### Validation prompt tips

For better validation results:

1. Start with action words such as:
   * validate
   * ensure
   * verify
   * require
   * check
2. Mention exact field names.
3. Describe the validation condition clearly.
4. Include valid and invalid examples for complex rules.
5. Mention how blank or null values should behave.

## AI generator for virtual columns

Generate computed or derived columns from natural-language instructions. Instead of writing JavaScript logic by hand, describe what the virtual column should calculate or return.

Useful for:

* Combining fields
* Calculated totals
* Derived statuses
* Formatting dates
* Extracting values
* Building custom labels

### Example prompts

#### Full name column

**Prompt**

```
Combine first_name and last_name columns with proper capitalization
```

**Expected behavior**

* `"john"` + `"DOE"` → `"John Doe"`

#### Total price calculation

**Prompt**

```
Multiply quantity and unit_price columns to create total_price
```

**Expected behavior**

* `quantity=5, unit_price=10.50` → `52.50`

#### Date formatting

**Prompt**

```
Convert dates from MM/DD/YYYY to Month DD, YYYY format
```

**Expected behavior**

* `"12/25/2023"` → `"December 25, 2023"`

#### Status generation

**Prompt**

```
Create a status column based on due_date
```

**Expected behavior**

* Past date → `"Overdue"`
* Within 7 days → `"Due Soon"`
* Future date → `"On Track"`

### Virtual column prompt tips

1. Mention which fields should be used.
2. Describe the expected output clearly.
3. Specify formatting rules.
4. Include examples for calculated logic.
5. Focus on one generated field at a time.

## AI generator for data transforms

Generate data transformation logic from plain-language instructions to clean, normalize, or reformat imported data automatically.

Useful for:

* Text normalization
* Formatting cleanup
* Phone number cleanup
* Date conversion
* Value mapping
* Row transformations

### Example prompts

#### Email standardization

**Prompt**

```
Convert email addresses to lowercase and remove leading or trailing spaces
```

**Expected behavior**

* `" John.Doe@Example.COM "` → `"john.doe@example.com"`

#### Phone number cleanup

**Prompt**

```
Remove all non-numeric characters from phone numbers
```

**Expected behavior**

* `"(555) 123-4567"` → `"5551234567"`

#### Full name generation

**Prompt**

```
Combine first_name and last_name columns with proper capitalization
```

**Expected behavior**

* `"john"` + `"DOE"` → `"John Doe"`

#### Date formatting

**Prompt**

```
Convert dates from MM/DD/YYYY format to YYYY-MM-DD
```

**Expected behavior**

* `"12/25/2023"` → `"2023-12-25"`

### Data transform prompt tips

1. Start with action words like:
   * convert
   * remove
   * replace
   * format
   * normalize
   * combine
2. Specify the target column.
3. Clearly describe the final output format.
4. Include sample input/output values for complex transforms.
5. Keep transformations focused and specific.

## AI generator for regex patterns

Generate regular expression (regex) patterns from plain-language descriptions. Instead of writing regex syntax by hand, describe the format you want to validate and CSVbox generates the pattern automatically.

Useful for:

* Email validation
* Phone number formats
* ZIP/postal codes
* Product code validation
* Password rules
* Custom formatting patterns

### Example prompts

#### Phone number validation

**Prompt**

```
exactly 10 digits, no spaces or dashes
```

**Generated pattern**

```regex theme={null}
/^[\d]{10}$/
```

#### Email validation

**Prompt**

```
valid email format with @ symbol and domain
```

**Generated pattern**

```regex theme={null}
/^[^\s@]+@[^\s@]+\.[^\s@]+$/
```

#### ZIP code validation

**Prompt**

```
5 digit US zip code, optionally followed by hyphen and 4 digits
```

**Generated pattern**

```regex theme={null}
/^\d{5}(-\d{4})?$/
```

#### Product code format

**Prompt**

```
product code starting with 2 uppercase letters followed by exactly 4 digits
```

**Generated pattern**

```regex theme={null}
/^[A-Z]{2}\d{4}$/
```

## Best practices

### Keep prompts focused

Short, focused prompts produce better results than large multi-step instructions.

Good:

```
Convert SKU values to uppercase
```

Less effective:

```
Convert SKU values to uppercase, remove spaces, validate duplicates, generate category names, and create status values
```

### Use exact column names

Prefer:

```
Combine first_name and last_name
```

Instead of:

```
Combine the user's names
```

### Mention formatting rules

Examples:

* `YYYY-MM-DD`
* `10 digit phone number`
* `uppercase product code`
* `currency with 2 decimals`

### Include examples for complex logic

Adding examples improves accuracy significantly. For example:

```
Convert dates from MM/DD/YYYY to YYYY-MM-DD. Example: 12/25/2023 → 2023-12-25
```

## Testing generated code

Always review and test generated code before saving.

Recommended testing steps:

1. Review the generated output.
2. Test with sample values.
3. Test blank and null values.
4. Verify edge cases.
5. Confirm expected formatting.
6. Ensure only intended fields are modified.

## Limitations

### Current limitations

* Generates JavaScript functions and regex patterns only.
* External APIs and network requests are not supported.
* Browser APIs like localStorage and cookies can't be used.
* Complex multi-step workflows may require multiple functions.

### Unsupported operations

The AI can't:

* Add or remove rows
* Modify your importer schema
* Access external systems
* Call third-party APIs
* Access databases
* Read files outside CSVbox
* Perform actions outside the CSVbox execution environment

## Common issues

### Generation failed

#### Possible causes

* Network issue
* Temporary server-side issue
* Prompt too complex
* Prompt too ambiguous

#### Solutions

* Retry after a few seconds.
* Simplify the prompt.
* Make instructions more specific.
* Break large logic into smaller prompts.

### Generated output is incorrect

#### Possible causes

* Missing formatting details
* Ambiguous instructions
* Missing edge cases
* Unclear expected output

#### Solutions

* Add input/output examples.
* Mention formatting rules explicitly.
* Specify null or blank value handling.
* Focus on one task at a time.

## Tips for better results

1. Use exact field names whenever possible.
2. Keep prompts concise and specific.
3. Mention edge cases such as blank values.
4. Include examples for complex rules.
5. Generate one function at a time.
6. Review generated code before saving.
7. Test thoroughly before production use.

## Security and safety

Generated code runs within the CSVbox execution environment and follows CSVbox security restrictions.

Generated functions can't:

* Access external systems
* Make network requests
* Access browser storage
* Modify importer configuration automatically

<Warning>
  Review and test all generated code before production use.
</Warning>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.