GenerateGenAIPrompt

You can use the GenerateGenAIPrompt function to retrieve and build a complete GenAIPrompt object from a Prompt Manager record.

Based on the specified prompt code, the function retrieves the corresponding Prompt Manager record and builds the prompt from the configured Goal, Prompt, Security & Trust Boundaries, Output Contract, and Normalization fields.

Note: Only the fields that contain values are included in the generated prompt.

The returned object also includes the associated model configuration, safety guardrail settings, and reasoning parameters specified in the prompt manager.

The result is a fully structured GenAIPrompt object that encapsulates all required information for GenAI execution. This object can be directly serialized into JSON format, making it ready for seamless integration with GenAI APIs and services.

When to use

You can use this function when:

  • You need the full GenAI request object for passing to a GenAI API call.
  • You need to access the model configuration, safety settings, or reasoning parameters in the prompt manager.

When not to use

You cannot use this function when:

  • You only need the generated prompt text.
    Note:  You can use GetGenAIPromptText to generate prompt text.
  • You need the value of a specific field from the prompt manager record.
    Note: You can use GetGenAIPromptText with the required field name.

Syntax

GenAIPrompt GenerateGenAIPrompt(string promptCode);

Parameters

Parameter Type Required Description
promptCode string Yes The identifier name of the prompt manager record to retrieve.
Note: This value must match a valid PROMPT_CODE in the FSPROMPTMANAGER table.

Return Value

The function returns a GenAIPrompt object with the following properties:

Property Type Description
model String The model name configured in the prompt manager record.
version String The model version configured in the prompt manager record.
prompt String The fully assembled prompt text
safetyGuardrail Boolean Indicates if safety guardrails are enabled
config.max_response Integer The maximum number of tokens allowed in the response.
config.temperature Integer The temperature setting controlling response variability (1–10).
config.reasoning.enabled Boolean Indicates if reasoning mode is enabled.
config.reasoning.budget_tokens Integer Token allocation for reasoning operations.

Prerequisites

The prompt code must be configured and active in the Prompt Manager.

JSON Output Sample

When serialized using the ToString() method, the object produces the following JSON structure:

{
  "model": "CLAUDE",
  "version": "claude-3-7-sonnet-20250219-v1:0",
  "prompt": "Summarize this document",
  "safetyGuardrail": true,
  "config": {
    "max_response": 20000,
    "temperature": 1,
    "reasoning": {
      "enabled": true,
      "budget_tokens": 12000
    }
  }
}

Examples

Example 1
Basic Usage: Retrieve GenAI Prompt.
using System;
using Formation.Shared.Defs.GenAI;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // Retrieve GenAI prompt object
        GenAIPrompt genAIPrompt = GenerateGenAIPrompt("TRANSLATE_RICH_TEXT");

        // Display model and prompt text
        MessageList("Model: " + genAIPrompt.model);
        MessageList("Prompt: " + genAIPrompt.prompt);

        return 1L;
    }
}
Description
This example retrieves the prompt configuration for TRANSLATE_RICH_TEXT and displays the model name and generated prompt text.
Example 2
Serialize Prompt for API Use.
using System;
using Formation.Shared.Defs.GenAI;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // Retrieve GenAI prompt object
        GenAIPrompt genAIPrompt = GenerateGenAIPrompt("TRANSLATE_RICH_TEXT");

        // Convert to JSON
        string jsonPayload = genAIPrompt.ToString();

        MessageList("Generated JSON Payload:");
        MessageList(jsonPayload);

        return 1L;
    }
}
Description
This example retrieves the GenAI prompt object for the specified prompt code TRANSLATE_RICH_TEXT converts it into a JSON payload.
Example 3
Access more Configuration Settings.
using System;
using Formation.Shared.Defs.GenAI;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // Retrieve GenAI prompt object
        GenAIPrompt genAIPrompt = GenerateGenAIPrompt("TRANSLATE_RICH_TEXT");

       // Access config values
        MessageList("Max Response Tokens: " + genAIPrompt.config.max_response);
        MessageList("Temperature: " + genAIPrompt.config.temperature);
        MessageList("Reasoning Enabled: " + genAIPrompt.config.reasoning.enabled);
        return 1L;
    }
}
Description
This example retrieves the GenAI prompt object for TRANSLATE_RICH_TEXT and displays its configuration values, such as max response tokens, temperature, and reasoning settings.
Example 4

Passing Dynamic Data to the Prompts.

Please find the sample prompt retrived from the prompt manager object FORMULA_AI_HELPER below:

Prompt
You are an AI Food Formulation Intelligence Engine that converts PLM formula data into a structured, UI-ready product dashboard.
Input
Read formula header data from [{HEADER_DATA}] and ingredient composition from [{INGREDIENT_DATA}].
Objective
Transform the data into a structured, visual, and insight-driven dashboard with consistent formatting across all executions.

GENAI_FRMLA_AIHELPER(Equation Script)

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Formation.Shared.Defs;
using Formation.Shared.Defs.GenAI;

class EquationScript : FcProcFuncSetEq
{
	public long evaluate()
	{
		string returnValue = "";
		long rc = 0;
		string checkPoint = "";

		try
		{
			GenAIPrompt GenAIPrmtObj = null;
			// get the prompt
			FcProcFuncSetEvent argcontext = this;
			GenAIPrmtObj = argcontext.GenerateGenAIPrompt("FORMULA_AI_HELPER");

			//Define columns to use in prompt replacement
			string[] ingrCols = { "ITEM_CODE", "QUANTITY", "UOM_CODE", "MATERIAL_PCT", "QTY_MASS", "RELQTY_PCT", "SECTION_TYPE", "TRADE_SECRET_NAME", "OPER_DESC", "ITEM_FUNCTION" };
			string[] headerCols = { "FORMULA_CODE", "VERSION", "DESCRIPTION", "UOM_CODE", "YIELD", "TOTAL_INGR_MASS", "TOTAL_INGR_VOL" };

			//mapping table columns to table
			var tableColumnMap = new Dictionary<string, string[]>
                {
                	{ "FSFORMULAINGR", ingrCols },
                	{ "FSFORMULA", headerCols }
                };

			var objectData = argcontext.Deserialize<Dictionary<string, DataTable>>(Context.EvaluateRequest.paramJson);

			// Store filtered tables separately
			var filteredTables = new Dictionary<string, DataTable>();

			// Filtering tables with only required column , avoids missing columns or invalid column errors
			foreach (var item in tableColumnMap)
			{
				if (objectData.TryGetValue(item.Key, out DataTable table))
				{
					filteredTables[item.Key] = table.DefaultView.ToTable(false, item.Value.Where(c => table.Columns.Contains(c)).ToArray());
				}
			}

			//Access required tables with filtered columns 
			var headerTable = filteredTables["FSFORMULA"];
			var ingredientTable = filteredTables["FSFORMULAINGR"];


			checkPoint = "Converting ingredient table to CSV";
			string headerCsv = argcontext.DataTableToCsv(headerTable);
			string ingredientCsv = argcontext.DataTableToCsv(ingredientTable);
			
			checkPoint = "Replacing prompt placeholders";
            GenAIPrmtObj.prompt = GenAIPrmtObj.prompt
                    .Replace("[{HEADER_DATA}]", headerCsv)
                    .Replace("[{INGREDIENT_DATA}]", ingredientCsv);

			returnValue = GenAIPrmtObj.ToString();

		}
		catch (Exception ex)
		{
			returnValue = "-1_" + checkPoint + ex.Message;
			rc = -1;
		}

		Context.ReturnValue = returnValue;
		return rc;
	}
}
Description
This example displays how to dynamically generate a GenAI request payload for formula analysis using the GenerateGenAIPrompt function.
The function retrieves the prompt configuration associated with the prompt code "FORMULA_AI_HELPER" and customizes the prompt by injecting runtime data.

The script extracts formula header and ingredient details from the input JSON (paramJson), filters only the required columns, and converts the data into CSV format.

These CSV values are then inserted into the prompt by replacing predefined placeholders ([{HEADER_DATA}] and [{INGREDIENT_DATA}]).

Finally, the updated prompt object is serialized into a JSON string and returned as the output.