LMS. - LM Studio Interface

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > LMS. - LM-Studio Commands >

LMS. - LM Studio Interface

LMS.SetJsonMode - Enforce JSON Output

Previous Top Next


MiniRobotLanguage (MRL)

 

LMS.Set JsonMode - Command

Force Valid JSON Responses

 

Intention

 

This command enables or disables JSON Mode. When enabled, the AI model is constrained to output only valid JSON syntax.

 

This is critical for automation scripts where you need to parse the AI's answer programmatically. Without JSON Mode, models often include chatty conversational text (e.g., "Here is the JSON you requested: ...") which breaks parsers.

With JSON Mode enabled, the response will contain raw JSON data only.

 

Syntax

 

LMS.Set JsonMode|P1

 

Parameter Explanation

 

P1 - (Integer) State flag.

1 = Enable JSON Mode.

0 = Disable JSON Mode (Default).

 

Example

 

'**********************************************

' LMS.setjsonmode - Data Extraction Example

'**********************************************

'

' 1. Enable JSON Mode

LMS.setjsonmode|1

'

' 2. IMPORTANT: Tell the model to use JSON in the prompt!

LMS.setsystemprompt|"You are a data extractor. Respond using JSON only."

'

' 3. Request Data

LMS.ask|"List the top 3 planets by size."|$$RES

'

' 4. Disable JSON Mode for normal chat later

LMS.setjsonmode|0

'

MBX.Raw Result: $$RES

 

Remarks

 

IMPORTANT: When JSON Mode is enabled, you must instruct the model to output JSON (via LMS.setsystemprompt or the prompt itself). If you don't, the model may get stuck or the server may reject the request.

 

This setting applies to both LMS.ask and LMS.askex commands. It effectively adds `"response_format": { "type": "json_object" }` to the API payload.

 

See also:

 

    LMS.setsystemprompt - Set Agent Persona

    LMS.ask - Basic AI Query