Using \input{} in inline mathmode -- extra }

I generate certain values and print them in single .tex-files (example.tex) in python, mostly in the form \SI{<value>}{\percent} or as single lines for tabular environments & \SI{<value>}{\percent} & \SI{<value>}{\percent} & \SI{<value>}{\percent}.

However, I can easily use \input{example.tex} to include this value in normal text,align or tabular environments without any trouble. But when using it within a mathmode (, , \ensuremath) of a table caption, the log files yields "...an extra }" at the place of input.

Pdflatex compiles and the value shows up, bit since the warning is an error, Id like to ask either:

1) Is the use of \input{} for this purpose generally recommended?
2) How to get rid of the error/what did I do wrong?


Below an MWE, test_size.tex consists purely of \SI{30}{\percent}.

\documentclass{article}

\usepackage{siunitx}
\usepackage{amsmath}

\begin{document}
Normal inline mode works: \input{./values/test_size.tex}\\[1ex]
Normal math inline mode works: $\input{./values/test_size.tex}$
\begin{table}
\caption{Math inline caption doesnt work: $\input{./values/test_size.tex}$}
\end{table}
\begin{align}
\textrm{align enviroment works: } \input{./values/test_size.tex}
\end{align}
\end{document}


EDIT: This would have helped as well. Sorry for double posting.

\input is an endangered species, it needs protection, use \protect\input instead.
• Cheers. Ive never spent much thought about why not or what else. I used \input to include different sections and so far for me it is the easiest way to automatically use values generated in my python projects. I assume there are better ways, and eager to read up on it. Could you provide me with some keywords? Mar 20 '20 at 16:26
• That sees overly complicated. But ok, you do you, I'd probably make a macro such that you could just use \ExtVal{test_size} instead of writing this all the time. Then it is also much easier if you later on decide to move the data to a different folder. Mar 20 '20 at 16:30
• Ah alright. I thought there are some other, more common ways without using \input in the first place. But sure, macros shorten my effort as well. Mar 20 '20 at 16:35