Task: workarena.servicenow.create-user
Goal: Create a new user with a value of "49226631434250493" for field "User ID", a value of "Davis-Adams" for field "Last name", a value of "David-Jon" for field "First name", a value of "david-jon.davis-adams@workarena.com" for field "Email", a value of "English" for field "Language", a value of "false" for field "Locked out", a value of "false" for field "Web service access only", a value of "true" for field "Active", a value of "(514) 341-5074" for field "Mobile phone", a value of "MM-dd-yyyy" for field "Date format", a value of "false" for field "Internal Integration User", a value of "oleoduct Chamacea photometrist gardeen Assmannshauser" for field "Title", a value of "(514) 144-7809" for field "Business phone", a value of "Europe/Dublin" for field "Time zone", a value of "Sales" for field "Department", and a value of "false" for field "Password needs reset".
Task configuration: {'table_name': 'sys_user', 'task_fields': ['user_name', 'last_name', 'first_name', 'email', 'preferred_language', 'locked_out', 'web_service_access_only', 'active', 'mobile_phone', 'date_format', 'internal_integration_user', 'title', 'phone', 'time_zone', 'department', 'password_needs_reset'], 'template_record': {'active': 'true', 'avatar': '', 'building': '', 'calendar_integration': 'Outlook', 'city': '', 'company': {'display_value': 'ACME Japan', 'link': 'https://dev215901.service-now.com/api/now/table/core_company/81fd65ecac1d55eb42a426568fc87a63'}, 'cost_center': {'display_value': 'Sales', 'link': 'https://dev215901.service-now.com/api/now/table/cmn_cost_center/7fb1cc99c0a80a6d30c04574d14c0acf'}, 'country': None, 'date_format': 'MM-dd-yyyy', 'default_perspective': '', 'department': 'Sales', 'email': 'david-jon.davis-adams@workarena.com', 'employee_number': '', 'enable_multifactor_authn': 'false', 'failed_attempts': '', 'first_name': 'David-Jon', 'gender': 'Male', 'home_phone': '', 'internal_integration_user': 'false', 'introduction': None, 'last_login': '', 'last_login_time': '', 'last_name': 'Davis-Adams', 'ldap_server': '', 'location': {'display_value': '2-12-1 Ookayama, Meguro-ku, Tokyo', 'link': 'https://dev215901.service-now.com/api/now/table/cmn_location/19020ca93790200044e0bfc8bcbe5dda'}, 'locked_out': 'false', 'manager': '', 'middle_name': '', 'mobile_phone': '(514) 341-5074', 'name': 'William Mahmud', 'notification': 'Enable', 'password_needs_reset': 'false', 'phone': '(514) 144-7809', 'photo': '', 'preferred_language': 'English', 'roles': '', 'schedule': '', 'source': '', 'state': '', 'street': '', 'sys_class_name': 'User', 'sys_created_by': 'admin', 'sys_created_on': '2012-02-17 19:04:53', 'sys_domain': {'display_value': 'global', 'link': 'https://dev215901.service-now.com/api/now/table/sys_user_group/global'}, 'sys_domain_path': '/', 'sys_id': '4f82abf03710200044e0bfc8bcbe5d3b', 'sys_mod_count': '5', 'sys_tags': '', 'sys_updated_by': 'developer.program.hop@snc', 'sys_updated_on': '2024-03-09 12:33:09', 'time_format': None, 'time_zone': 'Europe/Dublin', 'title': 'oleoduct Chamacea photometrist gardeen Assmannshauser', 'user_name': '49226631434250493', 'user_password': '********', 'vip': 'false', 'web_service_access_only': 'false', 'zip': ''}}

Validation code:
import json
import os
import re
import urllib.parse as parse
from typing import Any, Dict, List

import requests


def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    """
    Validate that a record was created with expected field values.
    Returns 1 on success, else 0.

    Expected config keys:
      - task_fields (list[str])                  # fields to validate
      - template_record (dict)                   # expected display values for those fields
    """

    # Check whether we have the necessary information to validate
    print(config)
    if "table_name" not in config or "task_fields" not in config or "template_record" not in config:
        raise ValueError("Target must contain 'table_name', 'task_fields' and 'template_record'")

    # Check whether we have messages
    if not messages:
        raise ValueError("Messages must not be empty")

    # Extract last message content
    content = messages[-1].get("content", "")

    # Extract all URLs — markdown links first, then bare URLs
    seen = set()
    urls = []
    for m in re.finditer(r"\[.*?\]\((https?://[^)]+)\)", content):
        url = m.group(1)
        if url not in seen:
            seen.add(url)
            urls.append(url)
    for m in re.finditer(r"https?://\S+", content):
        url = m.group(0).rstrip(")].,")
        if url not in seen:
            seen.add(url)
            urls.append(url)
    if not urls:
        return 0

    def extract_sys_id(url: str) -> str | None:
        """
        Return the 32-hex sys_id from a ServiceNow URL, or None if not found.
        Handles encoded target URLs like .../params/target/incident.do%3Fsys_id%3D<id>
        """
        # Unquote repeatedly (some SN URLs are doubly-encoded)
        for _ in range(3):
            new = parse.unquote(url)
            if new == url:
                break
            url = new

        m = re.search(r"(?:[?&])sys_id=([0-9a-f]{32})", url, re.IGNORECASE)
        return m.group(1) if m else None

    sys_id = None
    for raw_url in urls:
        current_url = parse.urlunparse(parse.urlparse(parse.unquote(raw_url)))
        sys_id = extract_sys_id(current_url)
        if sys_id:
            break
    if not sys_id:
        return 0

    # Query instance to get record
    response = requests.request(
        method="GET",
        url=os.getenv("SERVICENOW_INSTANCE_URL", "").rstrip("/") + f"/api/now/table/{config['table_name']}",
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("SERVICENOW_EXTRA_HTTP_HEADERS", "{}")),
        },
        params={
            "sysparm_query": f"sys_id={sys_id}",
            "sysparm_display_value": "true",
            "sysparm_fields": ",".join(config["task_fields"]),
        },
    )
    response.raise_for_status()
    if type(response) == dict:
        record = response
    else:
        record = response.json()

    if "result" in record:
        record = record["result"]

    if isinstance(record, list):
        if len(record) == 0:
            return 0
        record = record[0]

    # Check that the record matches the expected values
    for f in config["task_fields"]:
        val = record.get(f)
        # Handle nested display_value dicts from the API
        if isinstance(val, dict) and "display_value" in val:
            val = val["display_value"]
        if val is None:
            return 0
        if val != config["template_record"][f]:
            return 0
    return 1