Skip to main content

Dealing with syntax errors

Large Language Models are good at logical thinking, but their ability to generate error-free code is not as strong. The coding ability of the AI assistant depends on the amount of training data it has received. And the training data for PlantUML is limited, so the AI assistant may generate error code in some cases.

When this happens, the diagram renderer will display an error message, like this:

We are working on improving the AI assistant's coding ability, but for now, the best course of action is to correct the diagram code manually. You may need some PlantUML knowledge to do so.

How to read the error message

In the error message, like the one in the screenshot above, you will see the following information:

  • The line number where the error occurs: it's is the second line with the green background
  • The error message: it's the text in red, under the error line

Refer to the PlantUML Guide or the PlantUML Language Specification to identify the error based on what type of diagram you are creating.

How to fix the error

Once you have identified the error, you can fix it by editing the diagram code manually. You can switch to the Code editor mode to do so.

The diagram will be automaitcally re-rendered when you edit the code. If the error is fixed, the diagram will be rendered correctly. Otherwise, the error message will be displayed again.

How to ask AI to fix the error

You can also ask AI to fix the error for you, but it's not recommended. The outcome is unpredictable, and you might lose credit without getting any good result. If you still want to proceed, make sure you provide as much information about the error shown on the diagram in the AI request.

Common errors and how to fix them

Syntax error

The AI assistant may generate code with syntax errors. For example, the following code has a syntax error:

In an Activity diagram, the activity label should starts with : and ends with ;. In this case, the AI assistant has generated an activity label that both starts and ends with ". To fix this error, you can edit the code manually and change the " to : and ;:

Missing library imports

The AI assistant may generate C4 diagrams that starts and ends with @startc4 and @endc4. Or without the C4 module import. This will also result in a syntax error.

To fix this error, you can edit the code manually and add the C4 module import and remove the @startc4 and @endc4 tags:

!include <C4/C4_Container>