---
updatedAt: 2026-07-07T07:30:13.000Z
agentTools:
  projectIndex: https://docs.getembed.ai/llms.txt
---

# Validate & Test

Before deploying an algorithm, validate its syntax and test it against real data. This page covers the three endpoints that make up the authoring workflow: compose, validate, and test-run.

***

## Workflow

```
Write code (or Compose)
        │
   POST /algo/validate ──→ signature + syntax_check + security_check
        │
   POST /run/algo ──→ sandbox execution, returns feed + logs
        │
   POST /deploy/algos ──→ save (requires valid signature)
```

The `signature` from validation is required for both test-run and saving. You cannot skip validation.

***

## Compose: Generate from Natural Language

Generate algorithm code from a plain-English prompt:

```bash
curl -X POST https://api.mbd.xyz/v3/studio/algo/compose \
  -H "Authorization: Bearer mbd-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Create a feed of trending Polymarket markets about crypto, personalized to the user trading history",
    "version": "V1",
    "feed_type": "algorithm",
    "feed_inputs": "user_id"
  }'
```

### Response

```json
{
  "result": {
    "algorithm": "mbd.forUser(\"polymarket-wallets\", polymarketWallet);\nconst candidates = await mbd.search()...",
    "summary": "This algorithm searches for active Polymarket crypto markets..."
  }
}
```

* **algorithm** — generated JavaScript code ready to validate and test
* **summary** — human-readable explanation of what the algorithm does

### Parameters

| Parameter     | Type   | Description                                                          |
| ------------- | ------ | -------------------------------------------------------------------- |
| `prompt`      | string | Natural language description of the feed you want                    |
| `version`     | string | SDK version. Use `"V1"`                                              |
| `feed_type`   | string | `"algorithm"` (full StudioV1 pipeline) or `"minifeed"` (search-only) |
| `feed_inputs` | string | `"user_id"` — the input variable available to the algorithm          |

***

## Validate: Check Syntax and Security

Validate algorithm code before testing or saving:

```bash
curl -X POST https://api.mbd.xyz/v3/studio/algo/validate \
  -H "Authorization: Bearer mbd-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "algorithm": "const items = await search.index(\"polymarket-items\").include().numeric(\"volume_24hr\",1000).sortBy(\"volume_24hr\",\"desc\").size(10).execute(); search.show(items);",
    "version": "V1",
    "feed_type": "minifeed",
    "feed_inputs": "user_id"
  }'
```

### Response

```json
{
  "result": {
    "signature": "eyJhbGciOi...",
    "syntax_check": true,
    "security_check": true,
    "syntax_message": "OK",
    "security_message": "OK"
  }
}
```

* **signature** — JWT token required for test-run and saving. Encodes the validated code.
* **syntax\_check** — `true` if the code parses correctly
* **security\_check** — `true` if no dangerous patterns detected
* **syntax\_message** / **security\_message** — error details if checks fail

> **Important:** The `signature` is tied to the exact algorithm code. If you change the code, you must re-validate to get a new signature.

***

## Test Run: Execute in Sandbox

Run a validated algorithm against real data in a sandbox environment:

```bash
curl -X POST https://api.mbd.xyz/v3/studio/run/algo \
  -H "Authorization: Bearer mbd-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "feed_type": "algorithm",
    "feed_inputs": "user_id",
    "algorithm": "mbd.forUser(\"polymarket-wallets\", polymarketWallet); const items = await mbd.search().index(\"polymarket-items\").include().term(\"active\", true).sortBy(\"volume_24hr\",\"desc\").size(10).execute(); mbd.addCandidates(items); return mbd.getFeed();",
    "signature": "eyJhbGciOi...",
    "farcasterFid": "16085",
    "polymarketWallet": "0x1234...",
    "return_log": true
  }'
```

### Response

```json
{
  "result": {
    "feed": [
      {
        "_id": "661295",
        "_index": "polymarket-items",
        "_source": { "question": "Will BTC reach $150k?" }
      }
    ],
    "logs": ["Using Algorithm DSL version V1", "Search returned 10 candidates"]
  }
}
```

* **feed** — the algorithm's output items
* **logs** — any `log()` output from the algorithm code (only if `return_log: true`)

### Parameters

| Parameter          | Type    | Description                                           |
| ------------------ | ------- | ----------------------------------------------------- |
| `feed_type`        | string  | `"algorithm"` or `"minifeed"` (must match validation) |
| `feed_inputs`      | string  | `"user_id"` (must match validation)                   |
| `algorithm`        | string  | The algorithm code (must match what was validated)    |
| `signature`        | string  | The signature from `/algo/validate`                   |
| `farcasterFid`     | string  | Optional Farcaster FID for personalization            |
| `polymarketWallet` | string  | Optional wallet address for personalization           |
| `return_log`       | boolean | Include `log()` output in response                    |

### Sandbox Limits

* **Timeout:** 10 seconds
* **Available objects:** `mbd` (StudioV1 instance) for `algorithm` type, `search` (Search instance) for `minifeed` type
* **Available inputs:** `farcasterFid` and `polymarketWallet` are injected as variables

***

## Save: Deploy the Algorithm

Once validated and tested, save the algorithm:

```bash
curl -X POST https://api.mbd.xyz/v3/studio/deploy/algos \
  -H "Authorization: Bearer mbd-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Polymarket Trending Crypto",
    "description": "Trending crypto prediction markets personalized to user",
    "feed_type": "algorithm",
    "feed_inputs": "user_id",
    "algorithm": "...",
    "signature": "eyJhbGciOi...",
    "is_public": false
  }'
```

This returns an `algo_id` you can use in [Feed Configs](../Feeds/deploy-feed-configs).

***

## What's Next

* **[Feed Configs →](../Feeds/deploy-feed-configs)** Bundle your algorithm into a deployable feed config
* **[Search →](../Algorithm/search)** Deep dive into candidate generation
* **[API Reference: Validate](/reference/Algorithm/validate-and-compose/algovalidate)** — full endpoint spec
* **[API Reference: Test Run](/reference/Algorithm/test-run/feedbuilderrun)** — full endpoint spec