Create custom language operators
Language operators are the programmable Generative AI (GenAI)-powered building blocks of Conversation Intelligence. You can create custom language operators tailored to your specific use cases that Twilio-authored language operators might not address.
Custom language operators let you define and create your own language understanding tasks and perform conversational analysis that is:
- Unique to your business, tailored to your domain, terminology, and workflows
- Configurable, giving you full control over instructions and expected output
- Flexible, supporting both real-time and post-conversation use cases
You define what you want to extract using freeform instructions (prompt) and can optionally add context (Conversation Memory, Enterprise Knowledge) for more personalized and grounded results. The outcome is returned as a language operator result you can consume and activate in downstream systems.
The following are examples of custom language operators that augment human agents or trigger automation:
- Personalized greeting recommendations based on customer history and business context
- Real-time compliance checks to detect required disclosures or prohibited language
- Live objection handling using common objections unique to your products and services
- Custom lead qualification based on your proprietary scoring criteria
- Tailored summaries that are specific to your business and personalized to the customer
A custom language operator consists of the following components:
A prompt provides instructions for analyzing incoming conversations. You describe in natural language the task you want the language operator to perform with your conversations.
For guidance on how to write effective prompts, see Prompting best practices.
For examples, see Example use cases.
You can specify the desired output format (outputFormat) for your custom language operator:
TEXT: Plain text (default)JSON: Structured JSON objectCLASSIFICATION: Classifier string
When you provide a JSON schema, the language operator formats its output according to that schema. This helps ensure consistent and predictable results that are easier to parse and integrate with other systems.
Learn more about Structuring JSON schema.
Using parameters, custom language operators can accept dynamic inputs at runtime. Parameters make language operators configurable, reusable across intelligence configurations, and able to adapt their behavior based on the context of each conversation.
You must reference parameters directly in the language operator prompt using special syntax that substitutes the parameter values at runtime.
You define and use parameters in two places:
- Custom language operator: Where you define the parameter schema
- Intelligence configuration rule: Where you specify parameter values set at runtime
Together, these control how the language operator behaves during execution. When a rule triggers, the following occurs:
- Conversation Intelligence loads the language operator and its parameter schema.
- The intelligence configuration rule supplies parameter values.
- Default values are applied where values are not provided.
- The knowledge source content is resolved (if applicable).
- The prompt is rendered with parameter substitutions.
- The language operator executes using the combined prompt, parameters, and context.
Learn more about Defining parameters.
You can optionally enable context capabilities for your custom language operator. When enabled, the language operator can access contextual data during execution to:
- Personalize its output
- Use business or domain information
- Produce more accurate and relevant results
You enable context capabilities using two on/off toggles: one for Conversation Memory and one for Enterprise Knowledge.
When a language operator has Conversation Memory or Enterprise Knowledge enabled and becomes context-aware, it can query that data during execution. The language operator determines at runtime whether to use the provided context based on its relevance to the prompt and conversation transcript.
Learn more about business and customer data for language operators.
For context to work:
- The language operator must declare support for Conversation Memory or Enterprise Knowledge.
- The intelligence configuration rule must provide the context resources, such as customer profiles or knowledge bases.
Learn more about how language operators use knowledge search and memory tools.
You can provide training examples to help improve language operator results by contextualizing, clarifying, signaling intent, and adding specificity to your request.
Training examples consist of a sample input and the corresponding expected output:
- Input: Provide sample communications for the language operator to use as an example conversation
- Output: Provide what you would expect the language operator result to be for the given input
The language operator uses these examples to better understand the task you are asking it to perform.
To ensure the best possible results from your custom language operators, follow these prompting best practices:
-
Specify the task clearly and use explicit instructions:
Clearly state what you want the model to do, and specify the style or format of the response. This reduces ambiguity and ensures that the model provides the desired output.
Example: Instead of asking "Tell me about this customer", ask:
Provide a concise summary of the customer's needs with regard to moving and storage. -
Include context:
Providing relevant context can help the model generate more relevant and coherent responses, especially for complex queries.
Example:
Given our company's emphasis on recurring revenue over one-time purchases, how strong a lead is this prospect? -
Ask specific questions and limit open-ended inputs:
Formulate precise questions to elicit clear and focused responses. Narrow the scope to avoid broad or vague answers.
Example:
What are three key factors this customer is looking for in an insurance provider? -
Break down complex tasks:
For complex or multi-step tasks, consider breaking them into simpler, sequential prompts.
Example:
- Step 1: List the key moments in this conversation. - Step 2: Compare these with the following script. -
Use examples to guide format:
Offering a sample response can set expectations for the type and style of answer you anticipate.
Example:
Describe the key features the customer wants in a car. For instance, 'The customer is looking for a sports car with low mileage and a good infotainment system'.If you have multiple examples, consider using Training examples to provide these in a structured way.
-
Provide constraints when necessary:
Introducing constraints like word limits or particular formats can help control the output.
Example:
Summarize the conversation in 100 words or fewer.
Knowledge search and memory tools give language operators access to Enterprise Knowledge and Conversation Memory, enabling more accurate and personalized responses.
- Knowledge search tool: Performs semantic search over knowledge bases to retrieve documentation, policies, and product information.
- Memory tools: Provides access to historical context and user attributes for personalized responses. Memory tools include:
- Observational memory search tool: Searches observations automatically extracted from past conversations with the customer.
- Trait memory fetch tool: Fetches attributes explicitly set about a customer, such as name, preferences, and VIP status.
For a language operator to use these tools, set the following in the language operator configuration and intelligence configuration rule:
| Type | Operator | Intelligence configuration rule |
|---|---|---|
| Knowledge search tool | context.knowledge.enabled: true | context.knowledge.bases: ["<KNOWLEDGE_BASE_ID>"] |
| Memory tools | context.memory.enabled: true | N/A |
Note: Conversation Memory doesn't require additional configuration in the intelligence configuration rule because the system automatically handles user identification.
When knowledge search or memory tools are enabled in your operator and intelligence configuration, the language operator can invoke them during execution. While leaving this unguided works for some language operators, explicitly referencing the tool in the prompt can improve results.
To help the language operator correctly identify and use these tools, follow these best practices when writing your prompt:
-
Use the exact name: Always refer to the tool as the "knowledge search tool", "observational memory search tool", or "trait memory fetch tool" in the prompt. This ensures consistency with the tool's description and helps the language operator recognize it.
-
Structure your instruction: Use clear sections, such as "Goal" and "Steps".
- If the language operator should always use the tool, reference it in both the Goal and Steps sections.
- If the language operator should conditionally use the tool, clearly define the conditions in the Steps section.
-
Don't reference the knowledge base IDs in the prompt: The language operator doesn't understand them and might hallucinate. The language operator interacts with the knowledge search tool only using query strings.
1# Goal23Analyze the following transcript to determine if incorrect policy information was provided by the Agent45# Steps671. Read through the following transcript and identify if the agent provides any information related to company policy to the customer. Examples of this include the company's returns policy or service level agreement for faulty products.82. If no company policies were discussed, return 'no policies discussed'.93. If a company policy was discussed, you should use the knowledge search tool to search the official policy documentation. Use the results of the knowledge search tool to check if the agent provided any information that contradicted or was not present in the company's official policies. You should return a list of all incorrect policy information. You should include the information provided by the agent as well as the actual policy as identified by the knowledge search tool.
1# Goal23Analyze the following transcript to determine if the customer is making a repeated complaint. That is, if the current call includes any complaint that the customer has made in previous calls.45# Steps671. Identify all complaints that the customer has made in the transcript below.82. Use the observational memory search tool to search for any complaints in observational memory.93. Compare the complaints from the current transcript with the complaints from observational memory.10a. If there are matching complaints, return all matching complaints in the "repeated_complaints" list of the JSON response.11b. If there are no complaints in the current transcript, or no complaints in observational memory, or no matching complaints, set the "repeated_complaints" property to an empty list.
Use JSON schema to define the expected output structure when using structured JSON as the output format for your custom language operator.
A JSON schema for custom language operator results must be an object type. At minimum, a valid schema must include the following keywords:
type: Must be set toobjectproperties: An object defining the property names and their data types that the language operator should return
The following example shows a valid JSON schema for a tailored summarization use case:
1{2"type": "object",3"properties": {4"budget": { "type": "string" },5"authority": { "type": "string" },6"need": { "type": "string" },7"timeline": { "type": "string" }8}9}
When creating a JSON schema for your custom language operator, keep the following guidelines in mind:
- When you choose
outputFormat: JSON, you must provide a matching output schema (outputSchema), and the language operator's structured output will conform to this schema. See Troubleshooting: Response schema validation for failures related to response schema. - The root-level type of a JSON schema must be set to object.
- The following property data types are supported:
string,number,boolean,integer,object,array,enum,anyOf - Each output response has a maximum limit of 8,800 characters. To keep your output responses within this limit, follow these guidelines when designing the output schema:
- Flatten your JSON structure: Avoid overly nested JSON objects. Each nesting level adds extra characters when producing the JSON structure.
- Use efficient data types: Use Boolean (true/false) or integer (1/0) values for classifications.
- Abbreviate JSON property keys: Use concise, common abbreviations. For example, use
cust_idinstead ofcustomer_identification_number. - Minimize redundancy: Only include fields that are absolutely necessary for your downstream processes.
- Max 100 object properties and 5 levels of nesting are supported.
- Max 500 enum values across all enum properties are supported.
- Notable JSON Schema keywords not supported include:
- For strings:
minLength,maxLength,pattern,format - For numbers:
minimum,maximum,multipleOf - For objects:
patternProperties,unevaluatedProperties,propertyNames,minProperties,maxProperties - For arrays:
unevaluatedItems,contains,minContains,maxContains,minItems,maxItems,uniqueItems
- For strings:
- Structured language operator results will be returned in the same order as the keys in the schema.
- If the language operator refuses a language operator execution request for safety reasons, the language operator result will include a
refusalfield. - Twilio will automatically set
additionalPropertiestofalseand specify all provided fields as required (constraints of Structured Outputs). You don't need to pass these fields as part of your JSON schema. Twilio will automatically overwrite any user-provided values for these fields.
For additional JSON result schema examples, see Example use cases.
To review all available JSON schema syntax, see the JSON schema reference. You can also use JSON schema generators, such as transform.tools.
When creating a custom language operator, you define a parameter schema that describes:
- What parameters are available (parameter names)
- Parameter types
- Whether parameters are required
- Parameter default values (if applicable)
- How to reference parameters inside your prompt
Each parameter includes:
type: The data type. Supported types arestring,integer,number,boolean, andknowledge_base_and_source_ids.default: (Optional) A fallback value if the intelligence configuration doesn't provide onerequired: Whether the parameter must be provided at execution timedescription: A human-readable explanation of the parameter's purpose
The knowledge_base_and_source_ids parameter type allows a custom language operator to directly reference a specific knowledge source from a knowledge base. Use this for tasks like:
- Product-specific troubleshooting
- Policy-aware reasoning
- FAQ-informed agent guidance
The intelligence configuration rule passes the parameter value as a colon-separated string formatted:
<knowledge_base_id>:<knowledge_source_id>
- This parameter type only supports plain text knowledge sources.
- This parameter type doesn't support
defaultvalues.
When the language operator executes, it uses the provided knowledge base ID and knowledge source ID to look up the corresponding knowledge source.
At runtime, Twilio retrieves the plain text content of that knowledge source and injects it into the operator prompt.
The following example shows how to define a knowledge_base_and_source_ids parameter in your custom language operator's parameter schema:
1{2"type": "object",3"parameters": {4"policy_doc": {5"type": "knowledge_base_and_source_ids",6"required": true,7"description": "Policy document to reference for compliance checks."8}9}10}
1{2"parameters": {3"scale": {4"type": "integer",5"default": 5,6"required": true,7"description": "Maximum score for evaluating script adherence."8}9}10}
You can reference parameters in your prompt using the following syntax:
{{parameters.<param_name>}}
At runtime, Twilio replaces these tokens with the values supplied by your intelligence configuration rule. For example, if you have a parameter named length, you can reference it in your prompt like this:
Provide a {{parameters.length}}-length summary of this conversation.
Before creating a custom language operator, check if any Twilio-authored language operator meets your needs.
You can create a custom language operator using Twilio Console or the API.
When to use Twilio Console or the API
Twilio recommends using Twilio Console for most users. If you're an Independent Software Vendor (ISV) or use Infrastructure as Code (IaC) automation, use the API to programmatically create and manage custom language operators.
To create a custom language operator using Twilio Console:
- In Twilio Console, go to Products & services > Conversation Intelligence > Language operators and click Create operator.
- Follow the steps to create a custom language operator. The steps are:
- Create instructions.
- Add context capabilities.
- Review and save the custom language operator.