Source: docs/public/integration/prompt-integrations-example-foda.md
Prompt integration example: FODA matrix
End-to-end example of a prompt integration. Shows the manifest, the bundle,
and how the frontend consumes the endpoint.
Use case
An operator creates a prompt integration that generates a FODA (SWOT) matrix
from a business description. The integration accepts one text field and returns
four arrays.
---
Manifest
{
"version": 1,
"name": "foda_form",
"origin": "https://tu-empresa.com",
"data_classification": "non_sensitive",
"prompt": "Analizá el contexto recibido y devolvé solo JSON con strengths, weaknesses, opportunities y threats. Generá de cero a tres hallazgos breves por categoría, sin inventar datos. Una oración corta por hallazgo; listas vacías si falta evidencia. Sin Markdown ni HTML.",
"input_schema": {
"type": "object",
"additionalProperties": false,
"required": ["business_context"],
"properties": {
"business_context": {
"type": "string",
"minLength": 20,
"maxLength": 2000
}
}
},
"output_schema": {
"type": "object",
"additionalProperties": false,
"required": ["strengths", "weaknesses", "opportunities", "threats"],
"properties": {
"strengths": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"weaknesses": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"opportunities": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"threats": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } }
}
}
}
Supported schema subset
| Feature | Supported |
|---|---|
Root type: "object" | ✅ |
additionalProperties: false | ✅ |
required, properties | ✅ |
string with required maxLength, optional minLength | ✅ |
array with required maxItems / items, optional minItems | ✅ |
integer / number with bounds | ✅ |
boolean | ✅ |
| Nested objects | ✅ |
enum (strings, with maxLength required) | ✅ |
$ref, oneOf, anyOf, allOf, format, pattern | ❌ |
Both schemas are required at setup. New and updated integrations allow up to
2048 output tokens, including JSON syntax. Bounds are validation ceilings, not
a request to fill every category. Validate a real representative inference;
manifest validation alone does not prove generation fits or succeeds.
---
Bundle
The Admin API returns this after creating the manifest:
{
"id": "pi_a1b2c3d4e5f6",
"revision": 1,
"status": "active",
"endpoint": "https://api.forgium.dev/v1/prompt-integrations/pi_pub_x7y8z9w0/execute",
"origin": "https://tu-empresa.com",
"turnstile_sitekey": "0x4AAAAAAAxxxxxxxxxxxxxx",
"turnstile_action": "forgium_prompt_execute",
"input_schema": {
"type": "object",
"additionalProperties": false,
"required": ["business_context"],
"properties": {
"business_context": { "type": "string", "minLength": 20, "maxLength": 2000 }
}
},
"output_schema": {
"type": "object",
"additionalProperties": false,
"required": ["strengths", "weaknesses", "opportunities", "threats"],
"properties": {
"strengths": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"weaknesses": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"opportunities": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } },
"threats": { "type": "array", "maxItems": 3, "items": { "type": "string", "maxLength": 160 } }
}
}
}
The output schema is public metadata for building the response UI. Older bundles
may omit it; request the approved schema from the operator instead of guessing.
What is NOT in the bundle
| Field | Why |
|---|---|
prompt | Runs server-side only |
turnstile_secret | Never leaves the Worker |
| Admin paths | Not exposed in public docs |
---
Frontend integration
1. Load Turnstile
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit" defer></script>
Wait until the Turnstile script has loaded, then render with both sitekey
and action. See the complete loading example:
turnstile.render("#container", {
sitekey: "0x4AAAAAAAxxxxxxxxxxxxxx",
action: "forgium_prompt_execute", // mandatory
callback: (token) => { /* store token */ },
"expired-callback": () => { /* reset widget */ },
});
The action value comes from the bundle. It is not a secret.
2. Submit
const resp = await fetch("https://api.forgium.dev/v1/prompt-integrations/pi_pub_x7y8z9w0/execute", {
method: "POST",
signal: AbortSignal.timeout(30000),
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
input: { business_context: "..." },
turnstile_token: token,
}),
});
const body = await resp.json();
3. Handle response
Success:
{
"data": {
"strengths": ["Base de clientes existente"],
"weaknesses": ["Capacidad de entrega limitada"],
"opportunities": ["Consolidar pedidos recurrentes"],
"threats": []
}
}
Error:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "/business_context: must be string. Input must match input_schema. Fix the reported field."
}
}
4. Error codes
| Code | Status | Meaning |
|---|---|---|
ORIGIN_DENIED | 403 | Origin does not match manifest |
TURNSTILE_REQUIRED | 400 | Token missing |
TURNSTILE_INVALID | 403 | Verification failed, expired token, hostname or action mismatch |
INTEGRATION_DISABLED | 404 | Operator disabled the integration |
RATE_LIMITED | 429 | Per-IP burst limit (3/min) |
DAILY_QUOTA_EXCEEDED | 429 | Platform-configured daily attempt budget exhausted |
REQUEST_TOO_LARGE | 413 | Body exceeds limit |
VALIDATION_ERROR | 422 | Input does not match input_schema |
MODEL_OUTPUT_TRUNCATED | 502 | Model hit its output-token budget; no partial data is returned |
MODEL_OUTPUT_INVALID | 502 | Read message for missing model content, malformed JSON or the first output-schema failure |
INFERENCE_UNAVAILABLE | 503 | Model inference unavailable |
For either model-output error, report the code, UTC time and request trace ID
to the operator. Do not change the approved frontend contract, weaken validation
or automatically retry; these are Forgium-side failures. An incognito window
is not a repair. Failed inference attempts may still consume quota.
5. Reset Turnstile after every attempt
Tokens are single-use. Reset the widget after every submission, including
failures, before allowing another attempt.
turnstile.reset(widgetId);
---
Security rules for the frontend
- No secrets in client code. The bundle contains only public values.
Never include the prompt, API key, or Turnstile secret. The output schema is
public response metadata and can be used by the UI. - No innerHTML with backend data. Render
datafields as text, not HTML. - Validate input client-side. Enforce
minLength/maxLengthfrom the
schema before sending. - Respect Retry-After. For 429 responses, disable submission until the
retry window passes.
---
Full flow
Browser Forgium agent-api
│ │
│ POST /execute │
│ { input, turnstile_token } │
│ Origin: https://tu-empresa.com │
│ ─────────────────────────────────────▶ │
│ │
│ │ 1. Resolve integration
│ │ 2. Check Origin (exact)
│ │ 3. Rate limit (3/min per IP)
│ │ 4. Validate input schema
│ │ 5. Turnstile siteverify
│ │ 6. Reserve daily quota
│ │ 7. Model inference (JSON mode)
│ │ 8. Validate output schema
│ │
│ { "data": { ... } } │
│ ◀───────────────────────────────────── │