Hey @Oliver Wilms

I got a little lost reading your text, but have you tried adding some specific rules and examples to your prompt? Keywords like Use EXACTLY the following format, ATTENTION, and GOLDEN RULE usually help me get good results. Instead of something like The JSON array should look like this: try something like The Final Answer MUST contain ONLY the JSON array. Here is an example template for the JSON response: Another thing that makes a big difference is which model you're using with Ollama. I generally stick to SLMs (Smaller Language Models) on Ollama – those smaller, more specialized ones tend to work well.

something like that:
 

You are an expert in analyzing medical notes downloaded from patient portals.
ATTENTION: Your primary task is to extract specific information based on the questions below and structure it precisely into a JSON array.

GOLDEN RULE: The Final Answer MUST contain ONLY the JSON array. Do NOT include any introductory sentences, explanations, or any text outside of the JSON array itself.

Please follow these instructions carefully:
1.  You will be provided with a medical note.
2.  Read the note to identify answers to the six specific questions listed.
3.  Do NOT summarize the note or provide information not directly answering the questions.
4.  Construct a JSON array where each element is an object. Each object must contain two keys: "question" and "answer".
5.  If the answer to a specific question cannot be found in the provided medical note, the value for the "answer" key for that question MUST be an empty string (""). Do not guess or invent information.

Use EXACTLY the following structure for the JSON array and its elements.

Here is an example template for the JSON response:
[
  {
    "question": "What is the title or type of note?",
    "answer": "Example: Progress Note"
  },
  {
    "question": "What is the date the medical encounter took place?",
    "answer": "Example: 2023-10-26"
  },
  {
    "question": "What is the full name of the provider?",
    "answer": "Example: Dr. Jane Doe"
  },
  {
    "question": "What is the full name of the patient?",
    "answer": "Example: John Smith"
  },
  {
    "question": "Why did the patient have this encounter?",
    "answer": "Example: Follow-up for hypertension and medication check."
  },
  {
    "question": "What is the treatment plan of the provider?",
    "answer": "Example: Continue current medication, follow up in 3 months."
  }
]

The specific questions to answer are:
- What is the title or type of note?
- What is the date the medical encounter took place?
- What is the full name of the provider?
- What is the full name of the patient?
- Why did the patient have this encounter?
- What is the treatment plan of the provider?

---
[THE MEDICAL NOTE DOCUMENT WILL BE PLACED AFTER THIS LINE]
---

Hi,

Have you tried to make the namespace a binary value and pass the user and password as a parameter?

s Attr3=$lb(128,"intersystems-Namespace",$lb("%SYS"))
 s Attr4=$lb(0,"intersystems-Routine",$lb("iscRoutine"))
 s Attr5=$lb(0,"intersystems-Roles",$lb("iscRole1","iscRole2"))
 s Attr6=$lb(0,"userPassword",$lb(password))
 s Attr7=$lb(0,"cn",$lb("test20"))
 s Attr8=$lb(0,"uidNumber",$lb(58129))
 s Attr9=$lb(0,"gidNumber",$lb(58129))
 s Attr10=$lb(0,"homeDirectory",$lb("/home/test20"))
 s Attributes=$lb(Attr1,Attr2,Attr3,Attr4,Attr5,Attr6,Attr7,Attr8,Attr9,Attr10)
 s Status=##Class(%SYS.LDAP).AddExts(LD,DN,Attributes,"","")
 i Status'=$$$LDAPSUCCESS w !,"AddExts error: "_Status_" - "_##Class(%SYS.LDAP).Err2String(Status) g LDAPError

You can see an example of that on LDAP.mac on Namespace Samples.

I hope that helped you

Another option is to use a regular expression, like this:

ClassMethod ReplaceAccents(ByRef pWord As %String) As %Status
{
  Set tSC = $$$OK
  Try {
      Set dictionary = ##class(%ArrayOfDataTypes).%New()
      Do dictionary.SetAt("ÀÁÂÃÄÅ","A")
      Do dictionary.SetAt("àáâãäå","a")
      Do dictionary.SetAt("ÈÉÊË","E")
      //.... all the rest
   
      While dictionary.GetNext(.key) {
        Set matcher = ##class(%Regex.Matcher).%New("["_ dictionary.GetAt(key) _ "]", pWord)
        Set pWord = matcher.ReplaceAll(key)
      }
  Catch tException {
    Set:$$$ISOK(tSC) tSC = tException.AsStatus()
  }
  Quit tSC
}