HomeAboutAll PostsVideosSearchRSS

Applying SharePoint AI Autofill Prompts Programmatically

By Denis Molodtsov
Published in SharePoint
April 13, 2026
Updated November 05, 2026
3 min read
Applying SharePoint AI Autofill Prompts Programmatically
Table of contents

I had to roll out SharePoint autofill column prompts to about 170 columns across 20 sites, all by script. Surprisingly, it was not straightforward. Writing the prompt is the easy part, but a prompt set by script does nothing until autofill is switched on, and the calls that switch it on are not documented anywhere I could find. I worked them out by watching the browser’s developer tools while saving a column’s autofill settings, then repeated those calls from PowerShell.

Here are the exact steps, with no clicks in the UI.

Column with an Autofill prompt
Column with an Autofill prompt

All samples use PnP.PowerShell and assume you are connected to the site:

powershell
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/Knowledge" -UseWebLogin
$list = Get-PnPList -Identity "Documents"
$field = Get-PnPField -List $list -Identity "DocumentSummary"

To add a prompt to a column

Write the AutofillInfo attribute into the field’s SchemaXml:

powershell
$prompt = "Analyze the content and provide a brief 2-3 sentence overview."
$autofillInfo = @{
LLM = [ordered]@{
IsEnabled = $true
Prompt = $prompt
OverwriteMode = 0
ProcessingPass = 0
AutofillColumnType = "Unknown"
}
PrebuiltModel = $null
} | ConvertTo-Json -Compress -Depth 5
[xml]$xml = $field.SchemaXml
$xml.DocumentElement.SetAttribute("AutofillInfo", $autofillInfo)
$field.SchemaXml = $xml.DocumentElement.OuterXml
$field.Update()
Invoke-PnPQuery

To copy a prompt from another library

Take the attribute from the source field and write it the same way:

powershell
$src = Get-PnPField -List "Old Library" -Identity "DocumentSummary"
[xml]$srcXml = $src.SchemaXml
$autofillInfo = $srcXml.DocumentElement.GetAttribute("AutofillInfo")
[xml]$xml = $field.SchemaXml
$xml.DocumentElement.SetAttribute("AutofillInfo", $autofillInfo)
$field.SchemaXml = $xml.DocumentElement.OuterXml
$field.Update()
Invoke-PnPQuery

To switch autofill on

A stored prompt does nothing until autofill is switched on. Register each prompted column, then switch the library on:

powershell
$libId = "{$($list.Id)}"
# For each column with a prompt (off, then on, as the UI does)
foreach ($state in $false, $true) {
Invoke-PnPSPRestMethod -Method Post -Url "/_api/machinelearning/SetColumnLLMInfo" -ContentType "application/json" -Content @{
docLibId = $libId
columnId = $field.Id.ToString()
autofillPrompt = $prompt
isEnabled = $state
autofillColumnType = "Unknown"
}
}
# Once per library
Invoke-PnPSPRestMethod -Method Post -Url "/_api/machinelearning/SetAutofillColumnSettings" -ContentType "application/json" -Content @{
docLibId = $libId
autofillColumnSettings = '{"scenarioName":"AutoFillColumn"}'
}

From now on, every uploaded file is autofilled.

Side note: in my case, the values showed up in the columns within about a minute of each document being uploaded.

To check that autofill is on

powershell
Invoke-PnPSPRestMethod -Method Get -Url "/_api/machinelearning/GetAutofillColumnSettings(docLibId='$([uri]::EscapeDataString("{$($list.Id)}"))')"
Get-PnPField -List $list | Where-Object InternalName -like 'Prime*' | Select-Object InternalName

Autofill is on when the first line returns a value of {"scenarioName":"AutoFillColumn"} (not null) and the second lists five Prime* columns.

To autofill files that were already in the library

Autofill runs when a file is uploaded. Files that were in the library before autofill was switched on (migrated content, for example) stay empty, and so do files uploaded before you changed a prompt. Nothing in the library will go back and process them.

To get values on those files, you add each one to autofill’s processing queue: a POST to /_api/machinelearning/workItems with the file’s ID tells the service “run the prompts on this file”. The service picks it up within a minute or so and writes the values, exactly as if the file had just been uploaded. One request per file:

powershell
$siteId = (Get-PnPSite -Includes Id).Id.ToString()
$webId = (Get-PnPWeb -Includes Id).Id.ToString()
$files = Get-PnPListItem -List $list -PageSize 500 -Fields FileLeafRef, UniqueId, FSObjType |
Where-Object { $_["FSObjType"] -eq 0 }
foreach ($f in $files) {
Invoke-PnPSPRestMethod -Method Post -Url "/_api/machinelearning/workItems" -ContentType "application/json;odata=verbose" -Content @{
__metadata = @{ type = "Microsoft.Office.Server.ContentCenter.SPMachineLearningWorkItemEntityData" }
IsFolder = $false
ProfileName = "AutofillColumnsWriteback"
TargetSiteId = $siteId
TargetWebId = $webId
TargetUniqueId = $f["UniqueId"].ToString()
Type = "AE9D4F24-EE84-4C0C-A972-A74CFFE939A1"
}
}

Add a -like filter on FileLeafRef to try one or two files first.

Autofill values written to the queued files
Autofill values written to the queued files

To keep the AI inside your choice list

Generate the allowed values from the column’s own choices when you write the prompt, leave out values you never want, and say so in the prompt:

powershell
$template = @"
Identify the technology partners this document discusses.
Rules:
- Choose only from this list and copy each value exactly as written: {{VALUES}}
- Never return Contoso. Contoso wrote every document, so it is never a partner.
- Ignore every company that is not in the list. Do not return "Other" for it.
- If no value in the list applies, return nothing. Never return "N/A".
"@
$exclude = @("Other", "Contoso")
[xml]$xml = $field.SchemaXml
$values = @($xml.SelectNodes("//CHOICE") | ForEach-Object { $_.InnerText }) | Where-Object { $exclude -notcontains $_ }
$prompt = $template.Replace("{{VALUES}}", ($values -join "; "))

Then switch off “Can add values manually” on the column, so SharePoint never stores a value that is not a choice:

powershell
Set-PnPField -List $list -Identity $field.InternalName -Values @{ FillInChoice = $false }

More detail

Where the prompt is stored

The prompt is the AutofillInfo attribute on the column’s <Field> element, a JSON string:

json
{
"LLM": {
"IsEnabled": true,
"Prompt": "Review the document and provide a two sentence summary...",
"OverwriteMode": 0,
"ProcessingPass": 0,
"AutofillColumnType": "Unknown"
},
"PrebuiltModel": null
}

SchemaXml is the only writable route to it from PnP.PowerShell, which is why the samples above edit the XML.

Why the prompt alone does not fill any files

After you add the prompt, the column looks ready: the toggle in the column settings shows On and the column header has the sparkle icon. But uploaded files never get a value. The toggle only reads IsEnabled from the JSON above. The autofill service that actually reads documents and writes values keeps its own record of which libraries and columns are switched on, and adding the prompt does not update it. The /_api/machinelearning calls in “To switch autofill on” do. They are the same calls the page sends when you save a column’s autofill settings in the UI, captured from the browser.

Prompt in place, columns still empty
Prompt in place, columns still empty

The /_api/machinelearning endpoints

These are undocumented and relative to the site URL. docLibId is the library GUID in braces. columnId is the field GUID without braces.

EndpointMethodWhat it does
SetColumnLLMInfoPOSTRegisters a column’s prompt and turns the column on or off
GetColumnLLMInfo(docLibId='{...}',columnId='...')GETReturns the service’s record for one column
SetAutofillColumnSettingsPOSTSwitches autofill on for the library
GetAutofillColumnSettings(docLibId='{...}')GETReturns the library setting, or null if it was never switched on
workItemsPOSTQueues one existing file for processing

SetColumnLLMInfo body:

json
{
"docLibId": "{11111111-2222-3333-4444-555555555555}",
"columnId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"autofillPrompt": "Identify the technology partners this document discusses. ...",
"isEnabled": true,
"autofillColumnType": "Unknown"
}

GetColumnLLMInfo response:

json
{
"AutofillColumnType": "Unknown",
"IsEnabled": true,
"OverwriteMode": 0,
"ProcessingPass": "0",
"Prompt": "Identify the technology partners this document discusses. ..."
}

SetAutofillColumnSettings body. autofillColumnSettings is a JSON string, not an object:

json
{
"docLibId": "{11111111-2222-3333-4444-555555555555}",
"autofillColumnSettings": "{\"scenarioName\":\"AutoFillColumn\"}"
}

The “Prime” columns

Switching autofill on adds five hidden columns to the library. Add Processing status to a view to watch queued files move through.

Internal nameDisplay nameType
PrimeClassificationStatusProcessing statusSingle line of text
PrimeClassificationStatusDetailsProcessing detailsMultiple lines of text
PrimeLastClassifiedProcessedDate and Time
PrimeCorrectedByUserCorrectedYes/No
PrimeAutofillMetahiddennot shown in the UI

An activated library has its processing columns
An activated library has its processing columns

Choice lists

In a scored test of 61 documents against two long choice columns, the model returned no values outside the list once the list was in the prompt. The one problem was the author company: the model added it to 40 of 61 documents, because its name is on every page. Leaving it out of {{VALUES}} and naming it in the prompt fixed that. Generating {{VALUES}} from the column keeps the prompt and the choices in sync when someone adds a choice later.

Cost and timing

  • Autofill is billed per page processed, including every queued file. Skip files whose columns already have values.
  • Autofill does not change Modified or Modified By, and it does not create a new version. The values are written into the current version: a file uploaded as 1.0 stays at 1.0, with the autofilled values and a Processed time a minute after Modified.
  • When migrating content into a library, switch autofill on after the migration, or every copied file is processed, and billed, on arrival.

References

Found this useful? Follow me on LinkedIn to see my new posts.
Follow on LinkedIn

Tags

SharePointSharePoint OnlineAI in SharePointSyntexPnP PowerShellCSOMREST API

Share

Previous Article
Migrating File Shares to SharePoint - Operational Risks and Application Incompatibilities
Denis Molodtsov

Denis Molodtsov

Microsoft 365 Architect

Microsoft Most Valuable Professional (MVP)

Related Posts

SharePoint HTML pages, part 3, can they replace modern pages and web parts?
SharePoint HTML pages, part 3, can they replace modern pages and web parts?
November 01, 2026
11 min

Quick Links

AboutAll PostsRSS

Social Media